diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a942019..6f75c26 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1452,11 +1452,20 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ // DEBUG_WM(DEBUG_DEV,_numNetworks,(millis()-_lastscan )); // DEBUG_WM(DEBUG_DEV,"scanNetworks force:",force == true); #endif - if(_numNetworks == 0){ + + // if 0 networks, rescan @note this was a kludge, now disabling to test real cause ( maybe wifi not init etc) + // enable only if preload failed? + if(_numNetworks == 0 && _autoforcerescan){ DEBUG_WM(DEBUG_DEV,"NO APs found forcing new scan"); force = true; } - if(force || (_lastscan>0 && (millis()-_lastscan > 60000))){ + + // if scan is empty or stale (last scantime > _scancachetime), this avoids fast reloading wifi page and constant scan delayed page loads appearing to freeze. + if(!_lastscan || (_lastscan>0 && (millis()-_lastscan > _scancachetime))){ + force = true; + } + + if(force){ int8_t res; _startscan = millis(); if(async && _asyncScan){ @@ -3731,7 +3740,7 @@ String WiFiManager::WiFi_psk(bool persistent) const { WiFi.reconnect(); #endif } - else if(event == ARDUINO_EVENT_WIFI_SCAN_DONE){ + else if(event == ARDUINO_EVENT_WIFI_SCAN_DONE && _asyncScan){ uint16_t scans = WiFi.scanComplete(); WiFi_scanComplete(scans); } diff --git a/WiFiManager.h b/WiFiManager.h index 4c057ee..cedffab 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -544,10 +544,17 @@ class WiFiManager // async enables asyncronous scans, so they do not block anything // the refresh button bypasses cache // no aps found is problematic as scans are always going to want to run, leading to page load delays - boolean _preloadwifiscan = false; // preload wifiscan if true - boolean _asyncScan = false; // perform wifi network scan async - unsigned int _scancachetime = 30000; // ms cache time for background scans + // + // These settings really only make sense with _preloadwifiscan true + // but not limited to, we could run continuous background scans on various page hits, or xhr hits + // which would be better coupled with asyncscan + // atm preload is only done on root hit and startcp + boolean _preloadwifiscan = true; // preload wifiscan if true + unsigned int _scancachetime = 30000; // ms cache time for preload scans + boolean _asyncScan = true; // perform wifi network scan async + boolean _autoforcerescan = false; // automatically force rescan if scan networks is 0, ignoring cache + boolean _disableIpFields = false; // modify function of setShow_X_Fields(false), forces ip fields off instead of default show if set, eg. _staShowStaticFields=-1 String _wificountry = ""; // country code, @todo define in strings lang