You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When connecting to not responding server/port using WiFiClientSecure , connection timeout is always around 18s.
However, connection timeout works ok for the WiFiClient.
When looking at sources, WiFiClient::connect uses a common non-blocking socket connect pattern for receiving the desired timeout. This is not implemented in the start_ssl_client function used by WiFiClientSecure.
Is there a reason, why connection timeout is not implemented in the start_ssl_client function?
I've tried copy the initial connection pattern from WiFiClient::connect pattern to start_ssl_client and it works ok (unsurprisingly).
Testing code:
#include<WiFiClientSecure.h>constchar* ssid = "SSID "; // your network SSID (name of wifi network)constchar* password = "password"; // your network passwordconstchar* server = "www.howsmyssl.com"; // Server URLvoidsetup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
delay(100);
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
// attempt to connect to Wifi network:int i = 30;
while (WiFi.status() != WL_CONNECTED && --i) {
Serial.print(".");
// wait 1 second for re-tryingdelay(500);
}
if(WiFi.isConnected()) {
Serial.print("Connected to ");
Serial.println(ssid);
} else {
Serial.println("Connection failed ");
Serial.println("Restarting.. ");
ESP.restart();
}
WiFiClientSecure secClient;
secClient.setInsecure();
Serial.println("\nStarting secure connection to server...");
uint32_t start = millis();
int r = secClient.connect(server, 440, 5000);
Serial.printf("Connection took: %lums\n", millis()-start);
if(!r) {
Serial.println("Connection failed!");
} else {
Serial.println("Connected!");
secClient.stop();
}
WiFiClient client;
Serial.println("\nStarting unsecure connection to server...");
start = millis();
r = client.connect("192.168.1.3", 500, 3000);
Serial.printf("Connection took: %lums\n", millis()-start);
if(!r) {
Serial.println("Connection failed!");
} else {
Serial.println("Connected!");
client.stop();
}
}
voidloop() {
// do nothing
}
The text was updated successfully, but these errors were encountered:
vlastahajek
added a commit
to bonitoo-io/arduino-esp32
that referenced
this issue
Jul 19, 2021
Closes#5398
Using the same non-blocking socket connect pattern for respecting connection timeout, copied from WiFiClient::connect.
WiFiClient::connect uses lwip_connect_r, whereas start_ssl_client uses lwip_connect. I haven't found what is the difference between them. I tested both, both work ok, so I kept lwip_connect.
When connecting to not responding server/port using
WiFiClientSecure
, connection timeout is always around 18s.However, connection timeout works ok for the
WiFiClient
.When looking at sources, WiFiClient::connect uses a common non-blocking socket connect pattern for receiving the desired timeout. This is not implemented in the start_ssl_client function used by
WiFiClientSecure
.Is there a reason, why connection timeout is not implemented in the
start_ssl_client
function?I've tried copy the initial connection pattern from
WiFiClient::connect
pattern tostart_ssl_client
and it works ok (unsurprisingly).Testing code:
The text was updated successfully, but these errors were encountered: