Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/EasyWiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,17 @@ void EasyWiFi::startPortal() {
});

server.on("/scan", [this]() {
int networks = WiFi.scanNetworks();
Serial.printf("Scan complete: %d", networks);
int networks = WiFi.scanNetworks();

// Check for scan errors
if (networks < 0) {
Serial.printf("WiFi scan failed with error code: %d\n", networks);
server.send(500, "application/json",
"{\"error\":\"WiFi scan failed\",\"code\":" + String(networks) + "}");
return;
}

Serial.printf("Scan complete: %d networks found\n", networks);
String json = "[";

for (int i = 0; i < networks; i++) {
Expand All @@ -312,6 +321,7 @@ void EasyWiFi::startPortal() {
}
json += "]";

WiFi.scanDelete(); // Clean up scan results from memory
server.send(200, "application/json", json);
});

Expand Down