Fix WiFi setup

* Increased the number of APs that can be queried and filtered out those that have an RSSI -95.  Previously, the number of returned SSIDs could blow the output buffer.
* Do not disable the Save button during scan of potential APs.  If the scan is taking a long time you should just be able to type it in.
* If a connection is lost and cannot be recovered fall back to AP mode to allow resetting the creds without power off.
This commit is contained in:
Robert Strouse 2023-02-07 11:09:10 -08:00
parent dcd90a4c29
commit e1aada23b0
3 changed files with 46 additions and 22 deletions

22
Web.cpp
View file

@ -798,6 +798,25 @@ void Web::begin() {
Serial.print("Scanned ");
Serial.print(n);
Serial.println(" networks");
DynamicJsonDocument doc(16384);
JsonObject obj = doc.to<JsonObject>();
JsonObject connected = obj.createNestedObject("connected");
connected["name"] = settings.WIFI.ssid;
connected["passphrase"] = settings.WIFI.passphrase;
connected["strength"] = WiFi.RSSI();
connected["channel"] = WiFi.channel();
JsonArray arr = obj.createNestedArray("accessPoints");
for(int i = 0; i < n; ++i) {
if(WiFi.SSID(i).length() == 0 || WiFi.RSSI(i) < -95) continue; // Ignore hidden and weak networks that we cannot connect to anyway.
JsonObject a = arr.createNestedObject();
a["name"] = WiFi.SSID(i);
a["channel"] = WiFi.channel(i);
a["encryption"] = settings.WIFI.mapEncryptionType(WiFi.encryptionType(i));
a["strength"] = WiFi.RSSI(i);
a["macAddress"] = WiFi.BSSIDstr(i);
}
serializeJson(doc, g_content);
/*
String content = "{\"connected\": {\"name\":\"" + String(settings.WIFI.ssid) + "\",\"passphrase\":\"" + String(settings.WIFI.passphrase) + "\",\"strength\":" + WiFi.RSSI() + ",\"channel\":" + WiFi.channel() + "}, \"accessPoints\":[";
for (int i = 0; i < n; ++i) {
if (i != 0) content += ",";
@ -805,7 +824,8 @@ void Web::begin() {
delay(10);
}
content += "]}";
server.send(statusCode, "application/json", content);
*/
server.send(statusCode, "application/json", g_content);
});
server.on("/reboot", []() {
webServer.sendCORSHeaders();