Description
Board
ESP32 Dev Module
Device Description
Plain Devkit
Hardware Configuration
No
Version
v2.0.4
IDE Name
Arduino IDE
Operating System
Ubuntu something
Flash frequency
40Mhz
PSRAM enabled
no
Upload speed
460800
Description
@me-no-dev
The setConnectTimeout()
in HTTPClient -since 2.0.3 or 2.0.2- still has the problem that setConnectTimeout()
is not honored. I saw some commits and PRs #6676 and TD-er/ESPEasy@2c0ed04 that looked like they addressed the issue, but the issue is still there.
I checked out the HTTPClient source, but I don't have enough knowledge of the matter to solve it myself.
The following line of code in my current project does nothing usable since 2.0.3
_http->setConnectTimeout(url.startsWith("https") ? 2500 : 250);
And returns the following error:
[228558][I][WiFiClient.cpp:253] connect(): select returned due to timeout 250 ms for fd 48
[228558][W][HTTPClient.cpp:1469] returnError(): error(-1): connection refused
[228562][E][ESP32_VS1053_Stream.cpp:208] connecttohost(): [VS1053_Stream] error -1
When I check the time passed between the http request and error it is in the order of 60-65ms so something goes wrong there.
If I comment that line out, the connection is made in -again- 60-65ms.
Anybody recognise this, or better yet have a solution?
Sketch
/**
BasicHTTPClient.ino
Created on: 24.05.2015
*/
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#define USE_SERIAL Serial
WiFiMulti wifiMulti;
void setup() {
USE_SERIAL.begin(115200);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
for (uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
wifiMulti.addAP("SSID", "PSK");
}
void loop() {
// wait for WiFi connection
if ((wifiMulti.run() == WL_CONNECTED)) {
HTTPClient http;
USE_SERIAL.print("[HTTP] begin...\n");
http.setConnectTimeout(250);
const unsigned long START_TIME = millis();
http.begin("http://example.com/index.html"); //HTTP
USE_SERIAL.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
USE_SERIAL.printf("[DEBUG]time elapsed since start of request: %i ms\n\n\n", millis() - START_TIME);
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
USE_SERIAL.println(payload);
}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
delay(5000);
}
Debug Message
[HTTP] begin...
[HTTP] GET...
[120156][I][WiFiClient.cpp:253] connect(): select returned due to timeout 250 ms for fd 48
[120157][W][HTTPClient.cpp:1469] returnError(): error(-1): connection refused
[DEBUG]time elapsed since start of request: 6 ms
[HTTP] GET... failed, error: connection refused
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Activity
[-]HTTPClient [/-][+]HTTPClient setConnectTimeout issues.[/+]P-R-O-C-H-Y commentedon Aug 1, 2022
Hi @CelliesProjects, can you try it with changes from PR #6676 ?
CelliesProjects commentedon Aug 2, 2022
@P-R-O-C-H-Y I can but it will take a couple of days before I have some time.
Thanks for the suggestion, I will report back.
CelliesProjects commentedon Aug 2, 2022
@P-R-O-C-H-Y How do I checkout master in the arduino IDE environment?
P-R-O-C-H-Y commentedon Aug 2, 2022
@CelliesProjects Take a look here in our docs. There is a part with manual installation for Linux/MacOS and Windows. If you need any help, let me know :)
CelliesProjects commentedon Aug 3, 2022
@P-R-O-C-H-Y I could use some help. The PR is in your GH account. How do I pull that locally and use it? My git knowledge is very limited...
P-R-O-C-H-Y commentedon Aug 4, 2022
@CelliesProjects The PR is in this Arduino-esp32 repo, you don't need to download my fork.
git pull origin pull/6676/head
, that should apply all changes from PR to the master< > code
button, if you click that you can select Checkout with Github Desktop.schreibfaul1 commentedon Aug 11, 2022
Here is a simple example to show that there is a problem with the timeout
test case 1 (without timeout) works perfect, output
connected in 41 ms
test case 2 (timeout 200ms) not working, output
Connection Failed
this worked until version 2.0.2
CelliesProjects commentedon Aug 21, 2022
I just spend an hour trying to get the PR mentioned above on my laptop. I ended up with a lot of error messages so I probably f*cked that up.
I will retry again but the coming weeks I am very busy IRL.
21 remaining items