visit web

i am trying to save my external IP to my web page at my domain using arduino
this is my php script for save IP at xxxx.net

<html>  
  </head>
  <body>
  <?php        
        $data = $_SERVER['REMOTE_ADDR'];
        $file = "ip.txt";
        $file = fopen($file, "wa+");
        fwrite($file, $data);
        fclose($file);     
  ?>
  </body>
</html>

for arduino i use

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0x00, 0xAB, 0xCB, 0xCD, 0xDE, 0x02 };
IPAddress ip(192,168,1,43);
IPAddress server(0,0,0,0);

EthernetClient client;



void connect(){
  if (client.connect(server, 80)) {
      Serial.print("Make a HTTP request ... ");

     
      client.println("HOST: xxxx.net/xxx.php");
      client.println();

      Serial.println("ok");

    } 
    else {
      // kf you didn't get a connection to the server:
      Serial.println("connection failed");
  }
    
}

void setup() {
  Serial.begin(9600);  

  Serial.print("Setup LAN ... ");
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Ethernet.begin(mac, ip);
  Serial.println("ok");
  delay(1000);


  connect();
    
}

void loop(){

if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    delay(3000);

    connect();
  } 

}

and this is answer

<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.

</p>

i dont understand arduino. please help

That doesn’t make any sense.
The PHP script just logs the IP addresses of all HTTP requests to a file.

The Arduino script sends “HOST: xxxx.net - This website is for sale! - xxxx Resources and Information.” over a TCP connection to the server.
Your server is expecting an HTTP request, and you’re just sending text that it doesn’t understand, so it sends a 400 error.

Read up on the HTTP protocol.

Pieter

ok. i found this one. and it works

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

char server[] = "www.xxxx.net";   

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,1,43);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("SERIAL: Failed to configure Ethernet using DHCP");
  }

  // give the Ethernet shield a second to initialize:
  delay(1000);

  Serial.println("SERIAL: connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {

     client.print("GET /run.php");
     client.println(" HTTP/1.1");
     client.println("Host: www.xxxx.net");
     client.println("User-Agent: Arduino");
     client.println("Accept: text/html");
     client.println("Connection: close");
     client.println();

  }
  else {
    // if you didn't get a connection to the server:
    Serial.println("SERIAL: connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available, print them
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
 
}

now, i have problem how to repeat it every hour

mato85: now, i have problem how to repeat it every hour

I'm going to let you figure that out by yourself.