-->
Page 1 of 2

HTTP GET Requests

PostPosted: Mon Nov 30, 2015 11:41 am
by Daniel Dsouza
Hello,
Not sure if this is the right category for this doubt.

I'm trying to use HTTP GET requests on the esp.
Whenever i use GET requests with adafruit or google i get a response back . However if i use GET requests with my own site, it does not get a response back but the value gets updated in the databases. It does not enter the while(client.available()) loop.
As such i'm assuming that theres something probably wrong with my php script. If anyone has had any success in accomplishing this, let me know.

Thanks in advance.

Re: HTTP GET Requests

PostPosted: Tue Dec 01, 2015 8:14 am
by torntrousers
You really need to show your code, but as a guess it could be you don't wait long enough for the response. So if your code is something like this:
Code: Select all 
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");

  delay(10);   //  <<<********  10 is often too shorta delay
 
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){

then try increasing the delay value.

Re: HTTP GET Requests

PostPosted: Tue Dec 01, 2015 9:44 am
by martinayotte
Or even better, using a while loop which wait for a response until a timeout :

Code: Select all    int timeout = millis() + 5000;
    while (client.available() == 0) {
      if (timeout - millis() < 0) {
        p.println(">>> Client Timeout !");
        client.stop();
        return;
      }
    }

Re: HTTP GET Requests

PostPosted: Tue Dec 01, 2015 12:51 pm
by torntrousers
martinayotte wrote:Or even better, using a while loop which wait for a response until a timeout :

Code: Select all    int timeout = millis() + 5000;
    while (client.available() == 0) {
      if (timeout - millis() < 0) {
        p.println(">>> Client Timeout !");
        client.stop();
        return;
      }
    }


+1, though i also include a delay or yield in the loop to avoid the WDT, is that necessary?