Commit 02f06940 authored by PhiBo's avatar PhiBo 🚀

Improve ssid scan

parent 191c874c
...@@ -193,45 +193,44 @@ void handleScanSSID() ...@@ -193,45 +193,44 @@ void handleScanSSID()
String ssid; String ssid;
uint8_t first = 1; uint8_t first = 1;
// reserve some memory
data.reserve(600);
if (server->method() == HTTP_GET) { if (server->method() == HTTP_GET) {
query = server->arg("q"); query = server->arg("q");
int n = WiFi.scanNetworks(); int n = WiFi.scanNetworks();
if (n == 0) { data = "[";
server->send(404, "text/plain", "[]"); for (int i = 0; i < n; ++i) {
} else { ssid = WiFi.SSID(i);
data = "["; if(query.length() > 0 and !ssid.startsWith(query)) {
for (int i = 0; i < n; ++i) { continue;
ssid = WiFi.SSID(i); }
if(query.length() > 0 and !ssid.startsWith(query)) { if(first == 0) {
continue; data += ",";
} }
if(first == 0) { first = 0;
data += ","; data += "{\"ssid\"=\"";
} data += ssid;
first = 0; //data += "\",rssi=\"";
data += "{\"ssid\"=\""; //data += WiFi.RSSI(i);
data += ssid; data += "\",crypt=\"";
//data += "\",rssi=\""; if(WiFi.encryptionType(i) == ENC_TYPE_NONE) {
//data += WiFi.RSSI(i); data += "none";
data += "\",crypt=\""; } else if (WiFi.encryptionType(i) == ENC_TYPE_WEP) {
if(WiFi.encryptionType(i) == ENC_TYPE_NONE) { data += "wep";
data += "none"; } else if (WiFi.encryptionType(i) == ENC_TYPE_TKIP) {
} else if (WiFi.encryptionType(i) == ENC_TYPE_WEP) { data += "wpa";
data += "wep"; } else if (WiFi.encryptionType(i) == ENC_TYPE_CCMP) {
} else if (WiFi.encryptionType(i) == ENC_TYPE_TKIP) { data += "wpa2";
data += "wpa"; }
} else if (WiFi.encryptionType(i) == ENC_TYPE_CCMP) { data += "\"}";
data += "wpa2"; delay(10);
} if(data.length() > 512) {
data += "\"}"; break;
delay(10);
if(data.length() > 512) {
break;
}
} }
data += "]";
server->send(200, "text/plain", data);
} }
data += "]";
server->send(200, "application/json", data);
} }
} }
......
...@@ -61,11 +61,11 @@ void setup() { ...@@ -61,11 +61,11 @@ void setup() {
server->on("/action/register", handleRegister); server->on("/action/register", handleRegister);
server->on("/action/restart", handleRestart); server->on("/action/restart", handleRestart);
server->on("/action/save", handleSave); server->on("/action/save", handleSave);
server->on("/action/wifi/ssids", handleScanSSID);
server->on("/config/api/hostname", handleAPIHostname); server->on("/config/api/hostname", handleAPIHostname);
server->on("/config/api/port", handleAPIPort); server->on("/config/api/port", handleAPIPort);
server->on("/config/wifi/sta/ssid", handleSSID); server->on("/config/wifi/sta/ssid", handleSSID);
server->on("/config/wifi/sta/password", handlePassword); server->on("/config/wifi/sta/password", handlePassword);
server->on("/info/wifi/ssids", handleScanSSID);
server->on("/setup", []() { server->on("/setup", []() {
server->setContentLength(sizeof(PAGE_setup)); server->setContentLength(sizeof(PAGE_setup));
server->sendHeader("Content-Encoding", "gzip"); server->sendHeader("Content-Encoding", "gzip");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment