Skip to content

Commit

Permalink
Ability to set connect timeout in WifiMulti->run (#7420)
Browse files Browse the repository at this point in the history
* Adds timeout parameter to run

* Renaming varaible to connectTimeoutMs
  • Loading branch information
MikaelBertze committed Jul 1, 2020
1 parent 799c0f6 commit f1651fb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool ESP8266WiFiMulti::existsAP(const char* ssid, const char *passphrase) {
return APlistExists(ssid, passphrase);
}

wl_status_t ESP8266WiFiMulti::run(void) {
wl_status_t ESP8266WiFiMulti::run(uint32_t connectTimeoutMs) {

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

WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID);
status = WiFi.status();

static const uint32_t connectTimeout = 5000; //5s timeout

auto startTime = millis();
// wait for connection, fail, or timeout
while(status != WL_CONNECTED && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED && (millis() - startTime) <= connectTimeout) {
while(status != WL_CONNECTED && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED && (millis() - startTime) <= connectTimeoutMs) {
delay(10);
status = WiFi.status();
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/ESP8266WiFiMulti.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ESP8266WiFiMulti {
bool addAP(const char* ssid, const char *passphrase = NULL);
bool existsAP(const char* ssid, const char *passphrase = NULL);

wl_status_t run(void);
wl_status_t run(uint32_t connectTimeoutMs=5000);

void cleanAPlist(void);

Expand Down

0 comments on commit f1651fb

Please sign in to comment.