Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] WiFi periodic scanning #2088

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
9 changes: 8 additions & 1 deletion code/espurna/wifi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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<WiFiSleepType_t, _wifiSleepModeConvert>("wifiSleep", WIFI_SLEEP_MODE);
WiFi.setSleepMode(sleep_mode);
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion code/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down