From 2ded419486a6ed444195ce99e54f486b7bb8f792 Mon Sep 17 00:00:00 2001 From: FloX Date: Fri, 6 Apr 2018 18:10:06 +0200 Subject: [PATCH] Update WiFiMulti.cpp (#1220) * Update WiFiMulti.cpp added 5 sec timeout from ESP8266 * Update WiFiMulti.cpp * Update WiFiMulti.h --- libraries/WiFi/src/WiFiMulti.cpp | 9 +++++---- libraries/WiFi/src/WiFiMulti.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/WiFi/src/WiFiMulti.cpp b/libraries/WiFi/src/WiFiMulti.cpp index 41b40746..5a36cd6e 100644 --- a/libraries/WiFi/src/WiFiMulti.cpp +++ b/libraries/WiFi/src/WiFiMulti.cpp @@ -42,7 +42,7 @@ bool WiFiMulti::addAP(const char* ssid, const char *passphrase) return APlistAdd(ssid, passphrase); } -uint8_t WiFiMulti::run(void) +uint8_t WiFiMulti::run(uint32_t connectTimeout) { int8_t scanResult; @@ -117,9 +117,10 @@ uint8_t WiFiMulti::run(void) WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID); status = WiFi.status(); - - // wait for connection or fail - while(status != WL_CONNECTED && status != WL_NO_SSID_AVAIL && status != WL_CONNECT_FAILED) { + + 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) { delay(10); status = WiFi.status(); } diff --git a/libraries/WiFi/src/WiFiMulti.h b/libraries/WiFi/src/WiFiMulti.h index 500aada1..d9939953 100644 --- a/libraries/WiFi/src/WiFiMulti.h +++ b/libraries/WiFi/src/WiFiMulti.h @@ -54,7 +54,7 @@ public: bool addAP(const char* ssid, const char *passphrase = NULL); - uint8_t run(void); + uint8_t run(uint32_t connectTimeout=5000); private: std::vector APlist;