fix: single boot refresh with QR code, async WiFi scan, skip light sleep in AP mode
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -46,9 +46,25 @@ void AppWebServer::setupCaptivePortal() {
|
||||
request->send(LittleFS, "/setup.html", "text/html");
|
||||
});
|
||||
|
||||
// Handle WiFi scan
|
||||
// Kick off initial async WiFi scan
|
||||
WiFi.scanNetworks(true);
|
||||
|
||||
// Handle WiFi scan (non-blocking — returns cached results or "scanning" status)
|
||||
_server.on("/api/wifi/scan", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
int n = WiFi.scanNetworks();
|
||||
int n = WiFi.scanComplete();
|
||||
if (n == WIFI_SCAN_RUNNING) {
|
||||
// Scan in progress — tell client to retry
|
||||
request->send(200, "application/json", "{\"scanning\":true}");
|
||||
return;
|
||||
}
|
||||
if (n == WIFI_SCAN_FAILED) {
|
||||
// No scan started or failed — kick one off
|
||||
WiFi.scanNetworks(true);
|
||||
request->send(200, "application/json", "{\"scanning\":true}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Scan complete — return results
|
||||
JsonDocument doc;
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
@@ -59,6 +75,11 @@ void AppWebServer::setupCaptivePortal() {
|
||||
}
|
||||
String response;
|
||||
serializeJson(doc, response);
|
||||
|
||||
// Start a fresh scan for next request
|
||||
WiFi.scanDelete();
|
||||
WiFi.scanNetworks(true);
|
||||
|
||||
request->send(200, "application/json", response);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user