From b654e28641a1f3cb44e45d0dcaf850d8f6e49b4c Mon Sep 17 00:00:00 2001 From: nick Date: Thu, 4 Jun 2026 13:56:02 -0600 Subject: [PATCH] Fix WiFi priority reconnect and password preservation --- .../overland-controller.ino | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/firmware/esp32/overland-controller/overland-controller.ino b/firmware/esp32/overland-controller/overland-controller.ino index 0d4e4e3..c1f0af5 100644 --- a/firmware/esp32/overland-controller/overland-controller.ino +++ b/firmware/esp32/overland-controller/overland-controller.ino @@ -338,6 +338,11 @@ void connectStaWifi() { Serial.print(" to: "); Serial.println(staSsids[i]); + WiFi.disconnect(false, false); + delay(500); + WiFi.mode(WIFI_AP_STA); + delay(250); + WiFi.begin(staSsids[i].c_str(), staPasswords[i].c_str()); unsigned long start = millis(); @@ -1018,6 +1023,22 @@ void handleDebugSerial() { return; } + if (command == "wifi list") { + Serial.println("Saved WiFi networks:"); + for (int i = 0; i < wifiNetworkCount; i++) { + Serial.print(" "); + Serial.print(i + 1); + Serial.print(") priority "); + Serial.print(staPriorities[i]); + Serial.print(" / "); + Serial.print(staSsids[i]); + Serial.print(" / password_set "); + Serial.println(staPasswords[i].length() > 0 ? "true" : "false"); + } + return; + } + + if (command.startsWith("wifi ssid ")) { staSsids[0] = command.substring(10); staPriorities[0] = 1; @@ -1426,6 +1447,15 @@ void handleUpdateWifiConfig() { continue; } + if (password.length() == 0) { + for (int oldIndex = 0; oldIndex < MAX_WIFI_NETWORKS; oldIndex++) { + if (staSsids[oldIndex] == ssid && staPasswords[oldIndex].length() > 0) { + password = staPasswords[oldIndex]; + break; + } + } + } + int priority = network["priority"] | (wifiNetworkCount + 1); if (priority <= 0) priority = wifiNetworkCount + 1;