mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
fix savetimeout, too short, made optional
This commit is contained in:
+22
-4
@@ -247,7 +247,8 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
// @note @todo ESP32 has no autoconnect, so connectwifi will always be called unless user called begin etc before
|
||||
if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) {
|
||||
//connected
|
||||
DEBUG_WM(F("IP Address:"),WiFi.localIP());
|
||||
DEBUG_WM(F("AutoConnect: SUCCESS"));
|
||||
DEBUG_WM(F("STA IP Address:"),WiFi.localIP());
|
||||
_lastconxresult = WL_CONNECTED;
|
||||
|
||||
if((String)_hostname != ""){
|
||||
@@ -265,6 +266,8 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_WM(F("AutoConnect: FAILED"));
|
||||
|
||||
// not connected start configportal
|
||||
return startConfigPortal(apName, apPassword);
|
||||
}
|
||||
@@ -612,8 +615,13 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) {
|
||||
// if ssid argument provided connect to that
|
||||
if (ssid != "") {
|
||||
wifiConnectNew(ssid,pass);
|
||||
connRes = waitForConnectResult(_saveTimeout);
|
||||
}
|
||||
if(_saveTimeout > 0){
|
||||
connRes = waitForConnectResult(_saveTimeout); // use default save timeout for saves to prevent bugs in esp->waitforconnectresult loop
|
||||
}
|
||||
else {
|
||||
connRes = waitForConnectResult(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// connect using saved ssid if there is one
|
||||
if (WiFi_hasAutoConnect()) {
|
||||
@@ -724,6 +732,7 @@ void WiFiManager::updateConxResult(uint8_t status){
|
||||
|
||||
|
||||
uint8_t WiFiManager::waitForConnectResult() {
|
||||
if(_connectTimeout > 0) DEBUG_WM(DEBUG_VERBOSE,_connectTimeout,F("ms connectTimeout set"));
|
||||
return waitForConnectResult(_connectTimeout);
|
||||
}
|
||||
|
||||
@@ -739,7 +748,7 @@ uint8_t WiFiManager::waitForConnectResult(uint16_t timeout) {
|
||||
}
|
||||
|
||||
unsigned long timeoutmillis = millis() + timeout;
|
||||
DEBUG_WM(DEBUG_NOTIFY,timeout,F("ms connectTimeout set, waiting for connect...."));
|
||||
DEBUG_WM(DEBUG_VERBOSE,timeout,F("ms timeout, waiting for connect..."));
|
||||
uint8_t status = WiFi.status();
|
||||
|
||||
while(millis() < timeoutmillis) {
|
||||
@@ -1737,6 +1746,15 @@ void WiFiManager::setConnectTimeout(unsigned long seconds) {
|
||||
_connectTimeout = seconds * 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* [setConnectTimeout description
|
||||
* @access public
|
||||
* @param {[type]} unsigned long seconds [description]
|
||||
*/
|
||||
void WiFiManager::setSaveConnectTimeout(unsigned long seconds) {
|
||||
_saveTimeout = seconds * 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* [setDebugOutput description]
|
||||
* @access public
|
||||
|
||||
+3
-1
@@ -166,6 +166,8 @@ class WiFiManager
|
||||
|
||||
//sets timeout for which to attempt connecting, useful if you get a lot of failed connects
|
||||
void setConnectTimeout(unsigned long seconds);
|
||||
//sets timeout for which to attempt connecting on saves, useful if there are bugs in esp waitforconnectloop
|
||||
void setSaveConnectTimeout(unsigned long seconds);
|
||||
// toggle debug output
|
||||
void setDebugOutput(boolean debug);
|
||||
//defaults to not showing anything under 8% signal quality if called
|
||||
@@ -265,7 +267,7 @@ class WiFiManager
|
||||
// options flags
|
||||
unsigned long _configPortalTimeout = 0; // ms close config portal loop if set (depending on _cp/webClientCheck options)
|
||||
unsigned long _connectTimeout = 0; // ms stop trying to connect to ap if set
|
||||
unsigned long _saveTimeout = 5000; // ms stop trying to connect to ap on saves
|
||||
unsigned long _saveTimeout = 0; // ms stop trying to connect to ap on saves, in case bugs in esp waitforconnectresult
|
||||
unsigned long _configPortalStart = 0; // ms config portal start time (updated for timeouts)
|
||||
unsigned long _webPortalAccessed = 0; // ms last web access time
|
||||
WiFiMode_t _usermode = WIFI_OFF;
|
||||
|
||||
Reference in New Issue
Block a user