diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index a614f8fa2e..5a5d380d21 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -504,6 +504,14 @@ #define WIFI_SCAN_NETWORKS 1 // Perform a network scan before connecting #endif +#ifndef WIFI_PERIODIC_SCAN_INTERVAL +#define WIFI_PERIODIC_SCAN_INTERVAL 180000 // Perform a network scan while connected to find a better suited network. (time value in ms, default is 3 minutes) +#endif + +#ifndef WIFI_PERIODIC_SCAN_RANGE +#define WIFI_PERIODIC_SCAN_RANGE 20 // Minimum RSSI difference of a better network (absolute number, 0...127) +#endif + // Optional hardcoded configuration (up to 5 networks, depending on WIFI_MAX_NETWORKS and espurna/wifi_config.h) #ifndef WIFI1_SSID #define WIFI1_SSID "" diff --git a/code/espurna/wifi.ino b/code/espurna/wifi.ino index 331644d2b7..a58818a76d 100644 --- a/code/espurna/wifi.ino +++ b/code/espurna/wifi.ino @@ -124,8 +124,10 @@ void _wifiConfigure() { #if JUSTWIFI_ENABLE_SMARTCONFIG if (index == 0) _wifi_smartconfig_initial = true; #endif - + jw.enableScan(getSetting("wifiScan", 1 == WIFI_SCAN_NETWORKS)); + jw.setPeriodicScanInterval(getSetting("wifiScanIntvl", WIFI_PERIODIC_SCAN_INTERVAL)); + jw.setRSSIThreshold(getSetting("wifiScanRSSI", WIFI_PERIODIC_SCAN_RANGE)); const auto sleep_mode = getSetting("wifiSleep", WIFI_SLEEP_MODE); WiFi.setSleepMode(sleep_mode); @@ -284,6 +286,11 @@ void _wifiDebugCallback(justwifi_messages_t code, char * parameter) { DEBUG_MSG_P(PSTR("[WIFI] %s\n"), parameter); } + if (code == MESSAGE_FOUND_BETTER_NETWORK) { + DEBUG_MSG_P(PSTR("[WIFI] Reconnecting to %s\n"), parameter); + WiFi.disconnect(); + } + // ------------------------------------------------------------------------- if (code == MESSAGE_CONNECTING) { diff --git a/code/platformio.ini b/code/platformio.ini index 52682d0d08..7ad12e6900 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -115,7 +115,7 @@ lib_deps = https://bitbucket.org/xoseperez/fauxmoesp.git#3.1.0 https://github.com/xoseperez/hlw8012.git#1.1.0 https://github.com/markszabo/IRremoteESP8266#v2.2.0 - https://github.com/xoseperez/justwifi.git#2.0.2 + https://github.com/mcspr/justwifi.git#387e4df https://github.com/madpilot/mDNSResolver#4cfcda1 https://github.com/xoseperez/my92xx#3.0.1 https://github.com/256dpi/arduino-mqtt#196556b6