Skip to content

Commit acb1155

Browse files
committed
Implement timeout for waitForConnectResult
Fixes: #5330
1 parent 92b2046 commit acb1155

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Diff for: libraries/WiFi/src/WiFiSTA.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,14 @@ bool WiFiSTAClass::getAutoReconnect()
362362
* returns the status reached or disconnect if STA is off
363363
* @return wl_status_t
364364
*/
365-
uint8_t WiFiSTAClass::waitForConnectResult()
365+
uint8_t WiFiSTAClass::waitForConnectResult(unsigned long timeoutLength)
366366
{
367367
//1 and 3 have STA enabled
368368
if((WiFiGenericClass::getMode() & WIFI_MODE_STA) == 0) {
369369
return WL_DISCONNECTED;
370370
}
371-
int i = 0;
372-
while((!status() || status() >= WL_DISCONNECTED) && i++ < 100) {
371+
unsigned long start = millis();
372+
while((!status() || status() >= WL_DISCONNECTED) && (millis() - start) < timeoutLength) {
373373
delay(100);
374374
}
375375
return status();

Diff for: libraries/WiFi/src/WiFiSTA.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class WiFiSTAClass
5656
bool setAutoReconnect(bool autoReconnect);
5757
bool getAutoReconnect();
5858

59-
uint8_t waitForConnectResult();
59+
uint8_t waitForConnectResult(unsigned long timeoutLength = 60000);
6060

6161
// STA network info
6262
IPAddress localIP();

0 commit comments

Comments
 (0)