mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-26 09:59:01 +00:00
#561 - Add a scan for SSID
This commit is contained in:
parent
9f9573d2eb
commit
17297db2b1
@ -59,6 +59,7 @@ void handleStatic(HTTPRequest *req, HTTPResponse *res);
|
||||
void handleRestart(HTTPRequest *req, HTTPResponse *res);
|
||||
void handle404(HTTPRequest *req, HTTPResponse *res);
|
||||
void handleFormUpload(HTTPRequest *req, HTTPResponse *res);
|
||||
void handleScanNetworks(HTTPRequest *req, HTTPResponse *res);
|
||||
|
||||
void middlewareSpeedUp240(HTTPRequest *req, HTTPResponse *res, std::function<void()> next);
|
||||
void middlewareSpeedUp160(HTTPRequest *req, HTTPResponse *res, std::function<void()> next);
|
||||
@ -238,6 +239,7 @@ void initWebServer()
|
||||
ResourceNode *nodeRestart = new ResourceNode("/restart", "POST", &handleRestart);
|
||||
ResourceNode *node404 = new ResourceNode("", "GET", &handle404);
|
||||
ResourceNode *nodeFormUpload = new ResourceNode("/upload", "POST", &handleFormUpload);
|
||||
ResourceNode *nodeJsonScanNetworks = new ResourceNode("/json/scanNetworks", "GET", &handleScanNetworks);
|
||||
|
||||
// Secure nodes
|
||||
secureServer->registerNode(nodeAPIv1ToRadioOptions);
|
||||
@ -252,6 +254,7 @@ void initWebServer()
|
||||
secureServer->registerNode(nodeRestart);
|
||||
secureServer->setDefaultNode(node404);
|
||||
secureServer->setDefaultNode(nodeFormUpload);
|
||||
secureServer->setDefaultNode(nodeJsonScanNetworks);
|
||||
|
||||
secureServer->addMiddleware(&middlewareSpeedUp240);
|
||||
|
||||
@ -268,6 +271,7 @@ void initWebServer()
|
||||
insecureServer->registerNode(nodeRestart);
|
||||
insecureServer->setDefaultNode(node404);
|
||||
insecureServer->setDefaultNode(nodeFormUpload);
|
||||
insecureServer->setDefaultNode(nodeJsonScanNetworks);
|
||||
|
||||
insecureServer->addMiddleware(&middlewareSpeedUp160);
|
||||
|
||||
@ -906,6 +910,47 @@ void handleRestart(HTTPRequest *req, HTTPResponse *res)
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
void handleScanNetworks(HTTPRequest *req, HTTPResponse *res)
|
||||
{
|
||||
// res->setHeader("Content-Type", "application/json");
|
||||
res->setHeader("Content-Type", "text/html");
|
||||
|
||||
int n = WiFi.scanNetworks();
|
||||
res->println("{");
|
||||
res->println("\"data\": {");
|
||||
if (n == 0) {
|
||||
// No networks found.
|
||||
res->println("\"networks\": []");
|
||||
|
||||
} else {
|
||||
res->println("\"networks\": [");
|
||||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
char ssidArray[50];
|
||||
String(WiFi.SSID(i)).toCharArray(ssidArray, WiFi.SSID(i).length());
|
||||
|
||||
if (WiFi.encryptionType(i) != WIFI_AUTH_OPEN) {
|
||||
//res->println("{\"ssid\": \"%s\",\"rssi\": -75}, ", String(WiFi.SSID(i).c_str() );
|
||||
|
||||
res->printf("{\"ssid\": \"%s\",\"rssi\": %d}", ssidArray, WiFi.RSSI(i) ) ;
|
||||
//WiFi.RSSI(i)
|
||||
if (i != n-1) {
|
||||
res->printf(",");
|
||||
}
|
||||
}
|
||||
// Yield some cpu cycles to IP stack.
|
||||
// This is important in case the list is large and it takes us tome to return
|
||||
// to the main loop.
|
||||
yield();
|
||||
}
|
||||
res->println("]");
|
||||
}
|
||||
res->println("},");
|
||||
res->println("\"status\": \"ok\"");
|
||||
res->println("}");
|
||||
|
||||
}
|
||||
|
||||
void handleFavicon(HTTPRequest *req, HTTPResponse *res)
|
||||
{
|
||||
// Set Content-Type
|
||||
|
@ -40,6 +40,8 @@ bool isWifiAvailable()
|
||||
|
||||
// strcpy(radioConfig.preferences.wifi_ssid, "");
|
||||
// strcpy(radioConfig.preferences.wifi_password, "");
|
||||
strcpy(radioConfig.preferences.wifi_ssid, "meshtastic");
|
||||
strcpy(radioConfig.preferences.wifi_password, "meshtastic!");
|
||||
|
||||
if (*wifiName && *wifiPsw) {
|
||||
return 1;
|
||||
@ -75,7 +77,7 @@ void initWifi(bool forceSoftAP)
|
||||
|
||||
if (forceSoftAP) {
|
||||
// do nothing
|
||||
DEBUG_MSG("----- Forcing SoftAP\n");
|
||||
// DEBUG_MSG("----- Forcing SoftAP\n");
|
||||
} else {
|
||||
if (isWifiAvailable() == 0) {
|
||||
return;
|
||||
@ -93,7 +95,7 @@ void initWifi(bool forceSoftAP)
|
||||
if ((*wifiName && *wifiPsw) || forceSoftAP) {
|
||||
if (forceSoftAP) {
|
||||
|
||||
DEBUG_MSG("----- Forcing SoftAP\n");
|
||||
DEBUG_MSG("Forcing SoftAP\n");
|
||||
|
||||
const char *softAPssid = "meshtasticAdmin";
|
||||
const char *softAPpasswd = "12345678";
|
||||
|
Loading…
Reference in New Issue
Block a user