Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Pigs Fly
#19174 The code in the example sends the server request then waits an arbitrary 10mS for the response to begin, assumes that has happened and begins reading it regardless of whether the server has responded. If you have problems getting the server response (or knowing when it has taken place and completed) consider this change:

From example code:

Code: Select allclient.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  delay(10);
  // Read response here



More reliable code:

Code: Select allclient.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host: " + host + "\r\n" +
                 "Connection: close\r\n\r\n");

    //Wait up to 10 seconds for server to respond then read response
    int i=0;
    while((!client.available()) && (i<1000)){
      delay(10);
      i++;
    }
    //Read response here
   


Hopefully that helps someone when making multiple GETs in sequence so that things don't get too jammed up by beginning a new connection before the last one has finished.