Skip to content
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

Timeout set using Client::setTimeout is not taken into account in WiFiClient::connect #2120

Closed
hallard opened this issue Jun 8, 2016 · 4 comments

Comments

@hallard
Copy link
Contributor

hallard commented Jun 8, 2016

Hardware

Hardware: nodemcu ESP12
Core Version: latest git

Description

I think I misunderstood something, with HTTPClient library, I'm calling http.setTimeout(1000); it works once connected to server and when doing a http.get(). No pb at all
But whatever value I use if the server is down or not responding http.begin() seems to default to 5 seconds

Settings in IDE

Module: NodeMCU V1.0
Flash Size: 4MB/1MB
CPU Frequency: 160Mhz
Flash Mode: qio
Flash Frequency: 40Mhz
Upload Using: OTA
Reset Method: nodemcu

Sketch

Here my function

bool WS_post(char * host, uint16_t port, char * url)
{
  HTTPClient http;
  bool ret = false;

  // Just in case
  http.setTimeout(2000);

  Serial.printf("[HTTP] %s:%d/%s", host, port, url);

  // configure target server and url
  if ( http.begin(String(host), port, String(url)) )
  {
    // start connection and send HTTP header
    int httpCode = http.GET();

    // httpCode will be negative on error
    if (httpCode > 0) {
      // HTTP header has been send and Server response header has been handled
      Serial.printf("[HTTP] GET... code: %d\r\n", httpCode);

      // file found at server
      if (httpCode == HTTP_CODE_OK) {
        String payload = http.getString();

        Serial.printf("'%s' (%d ms)\r\n",payload.c_str(), millis()-start);
        ret = true;
      }
    } else {
      Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }
  } else {
    Serial.printf("[HTTP] Begin... error\r\n");
  }

  http.end();
  return ret;
}

Debug Messages

[HTTP] 80.11.xxx.xxx:82//?blablabla
after 5 seconds and not 2
[HTTP] GET... failed, error: connection refused

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@hallard hallard changed the title HTTPClient.setTimout(2000) not taken into account for begin() ? HTTPClient.setTimout(2000) not taken into account for http.begin() Jun 8, 2016
@hallard hallard changed the title HTTPClient.setTimout(2000) not taken into account for http.begin() http.setTimout(2000) not taken into account for http.begin() Jun 8, 2016
@hallard hallard changed the title http.setTimout(2000) not taken into account for http.begin() http.setTimout(2000) not taken into account for http.begin() ? Jun 10, 2016
@igrr igrr changed the title http.setTimout(2000) not taken into account for http.begin() ? Timeout set using Client::setTimeout is not taken into account in WiFiClient::connect Jun 12, 2016
@igrr igrr added this to the 2.4.0 milestone Jun 12, 2016
@josep112
Copy link

Hi,Hallard
You can solve this? I have the same problem

@Humancell
Copy link

I'm curious about the status of this? Particularly, I'm wanting to know what the default timeout is when using the WiFiClient client; / client.connect() call? And if I know the default, can I change this?

Likewise (slightly off topic) what is the default timeout on ESPhttpUpdate.update()? And is this also settable?

@mkeyno
Copy link

mkeyno commented Mar 2, 2017

for reliable performance or periodic remote HTTPClient request , I think HTTPClient should be rewritten in async mode, because sync stack has no correct idea about status of remote server and if you run the websocket server probably it will be failed

@igrr
Copy link
Member

igrr commented May 17, 2017

Will track this in #1420.

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

5 participants