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

Fix scan failures due to leftover connection information #180

Merged
merged 1 commit into from
Sep 21, 2024
Merged
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
11 changes: 10 additions & 1 deletion A/A.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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++) {
Expand Down
4 changes: 4 additions & 0 deletions B/B.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion boards.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
esp32:[email protected].4
esp32:[email protected].5
Loading