Fix WiFi priority reconnect and password preservation
This commit is contained in:
@@ -338,6 +338,11 @@ void connectStaWifi() {
|
|||||||
Serial.print(" to: ");
|
Serial.print(" to: ");
|
||||||
Serial.println(staSsids[i]);
|
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());
|
WiFi.begin(staSsids[i].c_str(), staPasswords[i].c_str());
|
||||||
|
|
||||||
unsigned long start = millis();
|
unsigned long start = millis();
|
||||||
@@ -1018,6 +1023,22 @@ void handleDebugSerial() {
|
|||||||
return;
|
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 ")) {
|
if (command.startsWith("wifi ssid ")) {
|
||||||
staSsids[0] = command.substring(10);
|
staSsids[0] = command.substring(10);
|
||||||
staPriorities[0] = 1;
|
staPriorities[0] = 1;
|
||||||
@@ -1426,6 +1447,15 @@ void handleUpdateWifiConfig() {
|
|||||||
continue;
|
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);
|
int priority = network["priority"] | (wifiNetworkCount + 1);
|
||||||
if (priority <= 0) priority = wifiNetworkCount + 1;
|
if (priority <= 0) priority = wifiNetworkCount + 1;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user