-
Notifications
You must be signed in to change notification settings - Fork 7.6k
HTTPClient setTimeout hasn't any effect #1433
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
Comments
You are using a method that I tried and did not work and it does not seem to be a timeout problem. const char* ssid = "Skynet"; int jd = 1234567; String url, payload; void setup(){ for (int i=0;i<1001;i++){
} void zap(){ void loop(){ } |
The timeout is in seconds. I don't think you mean 1000 seconds. |
I've just updated the esp32 firmware to the last version and still not working... Are you sure about measurement unit? In the esp8266 environment it should be in millisecond |
I am certain it is seconds, but you are correct that it is not working. That timeout can only be set once a connection is established. Chicken and egg problem. |
@lbernstone are you sure about Unless I'm very much mistaken (which is entirely possible) it looks like milliseconds to me. And if you set timeout as if in seconds, for example to 10, then http operations don't ever have a chance to complete, returning with a |
https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/src/WiFiClient.h#L83 |
But the issue refers to HTTPClient's setTimeout, https://github.com/espressif/arduino-esp32/blob/master/libraries/HTTPClient/src/HTTPClient.cpp#L309 which is referred to in milliseconds here https://github.com/espressif/arduino-esp32/blob/master/libraries/HTTPClient/src/HTTPClient.cpp#L994 |
The setTimeOut function in both WiFiClient AND HTTPClient is in SECONDS. Also, the setTimeOut can only be performed after a xxx.connect(). Not before! I learned this the hard way. |
Time out is in miliseconds and it works 100%. Means if httpResponseCode arrives promptly, httpResponseCode = 1, the code moves on. That is my understanding and it works precisely like that, I tested. |
I've jus tried again:
EDIT: Maybe this is the fix addressed by #2383 and already fixed |
No, that's a little different. The setTimeout here is only for the maximum connection time when you're already connected to the server. That's why it has no effect when the server is offline and you're stuck waiting 18+ seconds for that impossible connection to be established. The PR you linked is to set this connection timeout for WiFiClient. I just made a simple little PR to let you access this functionality via HTTPClient: #2606 Usage might be something like:
|
Now it is clear, thanks! |
@boardchuz it works. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
This stale issue has been automatically closed. Thank you for your contributions. |
The issue is still on, and it's quite serious and randomly occurring. |
any news ? |
set.Timeout still not having any effect on latest release (2.0.0), The timeout appears to be stuck at 30 seconds.
THIS WORKS
|
not sure if it works. I am keep getting it working on randomly basis. |
I agree that the Wi-Fi stack is really flaky and prone to crashes. In my previous experience, even a simple periodic HTTP client connection randomly crashed the whole thing, mainly due to bad exceptions management. However they have been constantly and massively improving it. Additionally it is running on bare metal microcontroller, there is no operating system with a kernel and protected mode. |
I am on 2.0.0. There is not much difference from 1.0.6. |
I see. In the current test I'm doing there is no light sleep as it has a AsyncWebServer running and must be available at any time. I have another firmware where there is only a HttpClient and light sleep would save some power, will test it there as well. |
Tested 2.0.3-RC1, timeout is now stuck to 30sec. I looked into your commit and it regards only secure connection, so it doesn't seem relevant to this issue. |
Thanks for testing, issue added to our Roadmap and we will investigate this further. |
Hi @fabianoriccardi. |
The timeout is reduced to 5seconds instead of >15seconds, but the timeout should be 1 seconds.. Here the report of a couple of iterations:
|
Can you try calling For what i see, its failing (timeouting) in connection, and not for data read. For Reading data you set 1000ms by Let us know, if that helps. |
I didn't know the existence of setConnectTimeout.. forgive me the issue was opened 4 years ago, I forget few details :) I tested both the functions with a proper API and they work as expected. However, the last issue is about http.setConnectTimeout(2800): it truncates the timeout to the "second", ignoring the "decimal part" (i.e. timeout 2800ms will last 2000ms). EDIT: Instead setTimeout is precise (i.e. subsecond timeouts are met) |
I am glad its working :) |
setConnectTimeout is in ms, but when passed to WifiClient:connect its converted to seconds by /1000. This may be changed in next minor version 2.1.0, you can take a look on prepared PR #6676 and checkout the changes manually for now. Maybe we can at least add the rounding as it is in HTTPClient:setTimeout before the PR get merged. |
Actually, I can continue to use the current stable version, but I was wondering why this unexpected behaviour is happening and I wanted to inform you. Thanks for your work and the patience! I think we can close the issue :) |
Thanks for you reports and quick answers :) So I am closing the issue, it can be always reopened ;) |
I have noticed that a couple of weeks ago some, but not all, of our deployed nodes stopped calling home once we took down the server for maintenance for a couple of hours. I don't know if setConnectTimeout() is at play or not. Will perform tests and if related will reopen the issue. |
Hardware:
Board: Lolin D32
Core Installation/update date: 24/May/2018
IDE name: Arduino IDE
Flash Frequency: 40Mhz
Upload Speed: 921600
Description:
While using the WiFiClient library, the method setTimeout() does't work. I mean, it seems always fixed to certain among (around 18seconds). The code is showed below...You can see that I call setTimeout twice to be sure to set the proper value, but still doesn't work.
The code below is reporting the library example, enriched with setTimeout() method.
Sketch:
Debug Messages:
The text was updated successfully, but these errors were encountered: