Skip to content

Commit f1651fb

Browse files
authored
Ability to set connect timeout in WifiMulti->run (#7420)
* Adds timeout parameter to run * Renaming varaible to connectTimeoutMs
1 parent 799c0f6 commit f1651fb

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bool ESP8266WiFiMulti::existsAP(const char* ssid, const char *passphrase) {
4646
return APlistExists(ssid, passphrase);
4747
}
4848

49-
wl_status_t ESP8266WiFiMulti::run(void) {
49+
wl_status_t ESP8266WiFiMulti::run(uint32_t connectTimeoutMs) {
5050

5151
wl_status_t status = WiFi.status();
5252
if(status == WL_DISCONNECTED || status == WL_NO_SSID_AVAIL || status == WL_IDLE_STATUS || status == WL_CONNECT_FAILED) {
@@ -132,12 +132,10 @@ wl_status_t ESP8266WiFiMulti::run(void) {
132132

133133
WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID);
134134
status = WiFi.status();
135-
136-
static const uint32_t connectTimeout = 5000; //5s timeout
137135

138136
auto startTime = millis();
139137
// wait for connection, fail, or timeout
140-
while(status != WL_CONNECTED && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED && (millis() - startTime) <= connectTimeout) {
138+
while(status != WL_CONNECTED && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED && (millis() - startTime) <= connectTimeoutMs) {
141139
delay(10);
142140
status = WiFi.status();
143141
}

libraries/ESP8266WiFi/src/ESP8266WiFiMulti.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ESP8266WiFiMulti {
5555
bool addAP(const char* ssid, const char *passphrase = NULL);
5656
bool existsAP(const char* ssid, const char *passphrase = NULL);
5757

58-
wl_status_t run(void);
58+
wl_status_t run(uint32_t connectTimeoutMs=5000);
5959

6060
void cleanAPlist(void);
6161

0 commit comments

Comments
 (0)