Skip to content

ESP8266HTTPClient does not consider timeout #3451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
schlaubstar opened this issue Jul 23, 2017 · 1 comment
Closed

ESP8266HTTPClient does not consider timeout #3451

schlaubstar opened this issue Jul 23, 2017 · 1 comment

Comments

@schlaubstar
Copy link

Basic Infos

Hardware

Hardware: ?ESP-12E?
Core Version: ?2.1.0-rc2?

Description

Using the method setTimeout(value) does not work. The given value is not taken into considerationwhen posting requests.

Settings in IDE

Module: ?ESP8266-12E Module?
Flash Size: ?4MB/1MB?
CPU Frequency: ?80Mhz?
Flash Mode: ?qio?
Flash Frequency: ?40Mhz?
Upload Using: ?SERIAL?

Sketch

#include <ESP8266WiFi.h> 
#include <ESP8266HTTPClient.h>
const boolean  deb PROGMEM =true ;                                   //if true, you will get debug messages

void setup() {
    
      if(deb) Serial.begin(115200);

    const char* ssid="mySSID";
    const char* pwd="myWIFIPassword";

    IPAddress ip(192,168,178,10);
    IPAddress gw(192,168,178,1);
    IPAddress sn(255,255,255,0);

    WiFi.persistent(false);            
    WiFi.mode(WIFI_STA);               
    WiFi.config(ip, gw, sn);   
    WiFi.begin(ssid, pwd);

    unsigned long start = millis();
    while(WiFi.status() != WL_CONNECTED)
    {
     if(deb) Serial.print(".");
     delay(50);
     if((millis() - start) > 5000)
       {
        if(deb) Serial.println("[WIFI   ] No Wifi connection after 5 seconds !");
        WiFi.mode(WIFI_OFF);
        WiFi.forceSleepBegin();
        ESP.deepSleep(60*100000);
        yield();
        }
    }
    
   
    unsigned long startt = millis();
//  >>>>>> THIS IS the relevant part to verify the problem     
    HTTPClient http;
    http.setTimeout(200);
    http.begin("http://192.168.178.20:8000/");
    http.addHeader("Content-Type", "text/plain");
    int httpCode = http.POST("This is just a sample text to post !");
   
    if(httpCode > 0) {
      if(deb) Serial.printf("[HTTP   ] POST... code: %d\n", httpCode);
        if(httpCode == HTTP_CODE_OK) {
          if(deb) Serial.println("[HTTP   ] POST... code was O.K ");
          String payload = http.getString();            //get return from Server 
          if (deb) Serial.println(payload);
        } 
                else { 
          if(deb) Serial.printf("[HTTP   ] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
                 }
  } else {
    if(deb) Serial.printf("[HTTP   ] POST... failed with code: %d, error: %s\n", httpCode, http.errorToString(httpCode).c_str());
    
  }
  http.end();
  yield();
  if(deb) Serial.printf("[HTTP   ] total duration of http-PUT: %d ms.\n", millis()- startt);
  ESP.deepSleep(60*100000);
 }
   

void loop() {
   //I won't get here ....
   ESP.deepSleep(60*100000);
}

Debug Messages

The above sketch was minimized and all crap not needed was removed. What I actually do is to measure some values via I2C bus and build a message, that is being sent to the server. As the server gets messages from several nodes it calculates a timespan and tells the sender of a post, how long to sleep before the receiver should wake up and transmit some new values - but this is unrelevant.

As you can see, I have set a timeout of 200 ms - You can change the value but what happens is the following (self created) debug output. It will transmit the data, and will get the message from the server

[HTTP   ] POST... code: 200
[HTTP   ] POST... code was O.K 
12345 //<this is the value my server sends me ...
[HTTP   ] total duration of http-PUT: 973 ms.

Basically: there seems to be an uninfluencable timout of 5000ms that I can not change.
What am I doing wrong?

@szczukot
Copy link

I think, that http.setTimeout(...) is only implemented for ead data. Not for connect and write.

igrr added a commit that referenced this issue Dec 28, 2017
Call Client::setTimeout before connection to influence connection
timeout.

Closes #3451.
@igrr igrr added this to the 2.4.0 milestone Dec 28, 2017
devyte pushed a commit that referenced this issue Dec 28, 2017
…#4038)

Call Client::setTimeout before connection to influence connection
timeout.

Closes #3451.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants