mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Ability to set connect timeout in WifiMulti->run (#7420)
* Adds timeout parameter to run * Renaming varaible to connectTimeoutMs
This commit is contained in:
parent
799c0f6774
commit
f1651fba89
@ -46,7 +46,7 @@ bool ESP8266WiFiMulti::existsAP(const char* ssid, const char *passphrase) {
|
|||||||
return APlistExists(ssid, 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();
|
wl_status_t status = WiFi.status();
|
||||||
if(status == WL_DISCONNECTED || status == WL_NO_SSID_AVAIL || status == WL_IDLE_STATUS || status == WL_CONNECT_FAILED) {
|
if(status == WL_DISCONNECTED || status == WL_NO_SSID_AVAIL || status == WL_IDLE_STATUS || status == WL_CONNECT_FAILED) {
|
||||||
@ -133,11 +133,9 @@ wl_status_t ESP8266WiFiMulti::run(void) {
|
|||||||
WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID);
|
WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID);
|
||||||
status = WiFi.status();
|
status = WiFi.status();
|
||||||
|
|
||||||
static const uint32_t connectTimeout = 5000; //5s timeout
|
|
||||||
|
|
||||||
auto startTime = millis();
|
auto startTime = millis();
|
||||||
// wait for connection, fail, or timeout
|
// 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);
|
delay(10);
|
||||||
status = WiFi.status();
|
status = WiFi.status();
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ class ESP8266WiFiMulti {
|
|||||||
bool addAP(const char* ssid, const char *passphrase = NULL);
|
bool addAP(const char* ssid, const char *passphrase = NULL);
|
||||||
bool existsAP(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);
|
void cleanAPlist(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user