Fix WiFi priority reconnect and password preservation

This commit is contained in:
2026-06-04 13:56:02 -06:00
parent 69c745e883
commit b654e28641
@@ -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;