From be3971d0810070e933de24157d04b077ce1c6d9e Mon Sep 17 00:00:00 2001 From: Just Call Me Koko Date: Mon, 8 Dec 2025 15:40:24 -0500 Subject: [PATCH 1/2] Wardriving is async --- esp32_marauder/WiFiScan.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index d5129c0..73de77f 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -4414,21 +4414,31 @@ void WiFiScan::executeWarDrive() { bool do_save; String display_string; - while (WiFi.scanComplete() == WIFI_SCAN_RUNNING) { + /*while (WiFi.scanComplete() == WIFI_SCAN_RUNNING) { Serial.println(F("Scan running...")); delay(500); + }*/ + + int scan_status = WiFi.scanComplete(); + + if (scan_status == WIFI_SCAN_RUNNING) { + delay(1); + return; + } + else if (scan_status == WIFI_SCAN_FAILED) { + Serial.println("WiFi scan failed to start"); } - #ifndef HAS_DUAL_BAND + /*#ifndef HAS_DUAL_BAND int n = WiFi.scanNetworks(false, true, false, 110, this->set_channel); #else int n = WiFi.scanNetworks(false, true, false, 110); - #endif + #endif*/ bool do_continue = false; - if (n > 0) { - for (int i = 0; i < n; i++) { + if (scan_status > 0) { + for (int i = 0; i < scan_status; i++) { do_continue = true; display_string = ""; do_save = false; @@ -4499,12 +4509,15 @@ void WiFiScan::executeWarDrive() { } } - #ifndef HAS_DUAL_BAND + /*#ifndef HAS_DUAL_BAND this->channelHop(); - #endif + #endif*/ // Free up that memory, you sexy devil WiFi.scanDelete(); + + if (!this->ble_scanning) + WiFi.scanNetworks(true, true, false, 80); } #endif } @@ -10131,9 +10144,11 @@ void WiFiScan::main(uint32_t currentTime) this->ble_scanning = false; } else { - pBLEScan->start(0, scanCompleteCB, false); - this->ble_scanning = true; - return; + if (WiFi.scanComplete() != WIFI_SCAN_RUNNING) { + pBLEScan->start(0, scanCompleteCB, false); + this->ble_scanning = true; + return; + } } #endif if (currentScanMode == BT_SCAN_FLOCK) From 2910addb8ae3719f357728b46107337bbc84c759 Mon Sep 17 00:00:00 2001 From: Just Call Me Koko Date: Mon, 8 Dec 2025 16:32:25 -0500 Subject: [PATCH 2/2] Ensure async wardrive --- esp32_marauder/WiFiScan.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index 73de77f..a2f49ca 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -2499,6 +2499,7 @@ void WiFiScan::StopScan(uint8_t scan_mode) #endif this->shutdownBLE(); + this->ble_scanning = false; #endif } @@ -4426,7 +4427,12 @@ void WiFiScan::executeWarDrive() { return; } else if (scan_status == WIFI_SCAN_FAILED) { - Serial.println("WiFi scan failed to start"); + Serial.println("WiFi scan failed to start. Restarting..."); + this->wifi_initialized = true; + this->shutdownWiFi(); + this->startWardriverWiFi(); + this->wifi_initialized = true; + delay(100); } /*#ifndef HAS_DUAL_BAND @@ -4507,15 +4513,15 @@ void WiFiScan::executeWarDrive() { buffer_obj.append(wardrive_line); } } + + // Free up that memory, you sexy devil + WiFi.scanDelete(); } /*#ifndef HAS_DUAL_BAND this->channelHop(); #endif*/ - // Free up that memory, you sexy devil - WiFi.scanDelete(); - if (!this->ble_scanning) WiFi.scanNetworks(true, true, false, 80); }