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?

dda
1,5951 gold badge12 silver badges17 bronze badges
asked Jan 28, 2017 at 14:16
7
  • Try changing char myserver[] = "www.myserver.com/"; to char myserver[] = "www.myserver.com"; (so without tailing slash) Commented Jan 28, 2017 at 14:21
  • Hi, I changed the line with char myserver[] = "www.myserver.com"; and now the serial monitor send "Connection failed to Server". :( Commented Jan 29, 2017 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... Commented Jan 29, 2017 at 15:03
  • Why create another variable ? Theproblem is that my shield does not connect to my server, Why ? Commented Jan 29, 2017 at 18:56
  • Apparently client.connect needs the slash at the end, while Host: required no slash at the end. Commented Jan 29, 2017 at 19:10

1 Answer 1

0

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

answered Jan 30, 2017 at 16:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.