Turning on wifi scan preload and async scanning, with hardcoded cachetime of 30seconds. Should make wifi page load faster, and make interface seem smoother. Will have to test with various enviroments and on S2/x3 chips
This commit is contained in:
tablatronix
2022-08-31 16:40:01 -05:00
parent 9abf5abdf6
commit d04d1f677b
2 changed files with 22 additions and 6 deletions
+12 -3
View File
@@ -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);
}
+10 -3
View File
@@ -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