From 22814fb7552726269031a2b819b33a18cbd11d82 Mon Sep 17 00:00:00 2001 From: Joseph Hewitt Date: Sat, 21 Sep 2024 22:30:27 +0200 Subject: [PATCH] Fix scan failures due to leftover connection information --- A/A.ino | 11 ++++++++++- B/B.ino | 4 ++++ boards.txt | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/A/A.ino b/A/A.ino index 7876ef2..17cd5d6 100644 --- a/A/A.ino +++ b/A/A.ino @@ -730,6 +730,9 @@ boolean check_for_updates(boolean stable=true, boolean download_now=false){ void setup_wifi(){ //Gets the WiFi ready for scanning by disconnecting from networks and changing mode. + //Turn off entirely to cleanup any references to active networks + WiFi.mode(WIFI_OFF); + delay(250); WiFi.mode(WIFI_STA); WiFi.disconnect(); } @@ -2471,14 +2474,20 @@ void setup() { void primary_scan_loop(void * parameter){ //This core will be dedicated entirely to WiFi scanning in an infinite loop. + setup_wifi(); while (true){ disp_wifi_count = wifi_count; wifi_count = 0; - setup_wifi(); for(int scan_channel = 1; scan_channel < 14; scan_channel++){ yield(); //scanNetworks(bool async, bool show_hidden, bool passive, uint32_t max_ms_per_chan, uint8_t channel) int n = WiFi.scanNetworks(false,true,false,110,scan_channel); + if (n < 0){ + //Got a scan error, add a delay to allow other tasks on this core to run and to hopefully let WiFi issues settle down + Serial.print("SCAN FAILURE "); + Serial.println(n); + delay(1000); + } if (n > 0){ wifi_count = wifi_count + n; for (int i = 0; i < n; i++) { diff --git a/B/B.ino b/B/B.ino index 52b33ad..7aa2ab4 100644 --- a/B/B.ino +++ b/B/B.ino @@ -46,6 +46,10 @@ int ble_found = 0; //The number of BLE devices found in a single scan, sent to s int wifi_scan_channel = 1; //The channel to scan (increments automatically) void setup_wifi(){ + //Gets the WiFi ready for scanning by disconnecting from networks and changing mode. + //Turn off entirely to cleanup any references to active networks + WiFi.mode(WIFI_OFF); + delay(250); WiFi.mode(WIFI_STA); WiFi.disconnect(); } diff --git a/boards.txt b/boards.txt index ba5f1f9..575cc5b 100644 --- a/boards.txt +++ b/boards.txt @@ -1 +1 @@ -esp32:esp32@3.0.4 +esp32:esp32@3.0.5