0

I have a very simple php web page that simply does "echo 0". When you type in the correct address, all you see is 0 on the page. So this is fine. I am trying to activate this php page with my arduino code and get this "0" from the site, however it keeps returning this "HTTP/1.1 200 OK" instead of this "0". What am I missing? Here is the arduino code that is relevant...

void printWEB(WiFiClient client) {

if (client.connect(localServer, 80) == 1) {
client.print("GET /waterStatus.php?username=test&device_column=d1");  
client.println(" HTTP/1.1"); // Part of the GET request
client.println("Host: www.MYURL.com");
client.println("User-Agent: ESP8266/1.0");
client.println("Connection: close");
client.println();


 unsigned long timeoutP = millis();
 while (client.available() == 0) {
   if (millis() - timeoutP > 10000) {
      Serial.print(">>> Client Timeout: ");
      Serial.println("www.MYURL.com");
      client.stop();
      return;
   }
 }
  while(client.available()){
    String retLine = client.readStringUntil('\r');
    Serial.println(retLine);
    break; 
  }
}
delay(1000);

}

this last line "Serial.println(retLine);" is what I am expecting to be 0 but it is not.

6
  • 1
    The response from your web server includes one or more headers including the response code you are seeing. The response you are looking for is further down. Commented Mar 1, 2021 at 0:15
  • So how do I get to it? do another readuntil? Commented Mar 1, 2021 at 0:17
  • Yes, probably more than one. You're currently only reading until you see a carriage-return. You should read until there's no more data. Commented Mar 1, 2021 at 0:21
  • Is there a cleaner way? Commented Mar 1, 2021 at 0:22
  • You're working with an HTTP message here, not a web page. A browser will strip and interpret all the headers and present just the body for display. If you're handling the message you'll need to do that yourself. I'm not familiar with Arduino's library classes. There might be a readAll() method you can use. I believe there's an experimental HttpClient library that might do some of this for you. Commented Mar 1, 2021 at 0:45

0

Your Answer

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.