0

I am trying to send data via GET to my PHP server from my Ethernet Shield2. This is part of my sketch:

char myserver[] = "www.myserver.com/";
if (client.connect(myserver, 80)) {
  Serial.print("Connected to ");
  Serial.println(myserver);
  client.print("GET /arduino/controller.php?");
  client.print("air_temp=");
  client.print(DS18B20_temperature);
  client.println(" HTTP/1.1");
  client.print("Host: ");
  client.println(myserver);
  client.println("Connection: close");
  client.println();
  client.println();
} else {
  // if you didn't get a connection to the server:
  Serial.println("Connection failed to Server");
}

The serial monitor displays "Connect to myserver.com" but my PHP code doesn't seem to receive the air_temp value from DS18B20_temperature. I checked this value and it's true.

However, when I try myserver.com/arduino/controller.php?air_temp=25 in my browser, the PHP code is running well.

What's going wrong with my code?

  • Try changing char myserver[] = "www.myserver.com/"; to char myserver[] = "www.myserver.com"; (so without tailing slash) – Gerben Jan 28 '17 at 14:21
  • Hi, I changed the line with char myserver[] = "www.myserver.com"; and now the serial monitor send "Connection failed to Server". :( – Teddol Jan 29 '17 at 13:37
  • There shouldn't be a slash in the Host header. So create a second variable, without the slash and use that one in line behind Host... – Gerben Jan 29 '17 at 15:03
  • Why create another variable ? Theproblem is that my shield does not connect to my server, Why ? – Teddol Jan 29 '17 at 18:56
  • Apparently client.connect needs the slash at the end, while Host: required no slash at the end. – Gerben Jan 29 '17 at 19:10
0

I just removed the line server.begin() and it's works !!! Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.