Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit 6a10866

Browse files
committed
Update WiFi timeout condition (fixes #122)
1 parent 9980787 commit 6a10866

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/WiFiManager.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void WifiManager::begin(char const *apName, unsigned long newTimeout)
3939
WiFi.begin();
4040
}
4141

42-
if (WiFi.waitForConnectResult(timeout) == WL_CONNECTED)
42+
if (waitForConnectResult(timeout) == WL_CONNECTED)
4343
{
4444
//connected
4545
Serial.println(PSTR("Connected to stored WiFi details"));
@@ -52,6 +52,23 @@ void WifiManager::begin(char const *apName, unsigned long newTimeout)
5252
}
5353
}
5454

55+
//Upgraded default waitForConnectResult function to incorporate WL_NO_SSID_AVAIL, fixes issue #122
56+
int8_t WifiManager::waitForConnectResult(unsigned long timeoutLength) {
57+
//1 and 3 have STA enabled
58+
if((wifi_get_opmode() & 1) == 0) {
59+
return WL_DISCONNECTED;
60+
}
61+
using esp8266::polledTimeout::oneShot;
62+
oneShot timeout(timeoutLength); // number of milliseconds to wait before returning timeout error
63+
while(!timeout) {
64+
yield();
65+
if(WiFi.status() != WL_DISCONNECTED && WiFi.status() != WL_NO_SSID_AVAIL) {
66+
return WiFi.status();
67+
}
68+
}
69+
return -1; // -1 indicates timeout
70+
}
71+
5572
//function to forget current WiFi details and start a captive portal
5673
void WifiManager::forget()
5774
{

src/WiFiManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class WifiManager
2525
void stopCaptivePortal();
2626
void connectNewWifi(String newSSID, String newPass);
2727
void storeToEEPROM();
28+
int8_t waitForConnectResult(unsigned long timeoutLength);
2829

2930
public :
3031
void begin(char const *apName, unsigned long newTimeout = 60000);

0 commit comments

Comments
 (0)