mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-07-09 23:25:45 +00:00
added logic for loading available networks
This commit is contained in:
parent
5c5e8e9e5a
commit
12aa87ac90
7 changed files with 145 additions and 11 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "config.h"
|
||||
#include <stdexcept>
|
||||
#include <ArduinoJson.h>
|
||||
#include "WiFi.h"
|
||||
|
||||
Preferences config;
|
||||
|
||||
|
@ -161,3 +162,31 @@ void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size
|
|||
request->send(400, "text/plain", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void onGetNetworks(AsyncWebServerRequest *request)
|
||||
{
|
||||
JsonDocument doc;
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
|
||||
int numberOfNetworks = WiFi.scanComplete();
|
||||
if (numberOfNetworks == WIFI_SCAN_FAILED)
|
||||
{
|
||||
WiFi.scanNetworks(true);
|
||||
}
|
||||
else if (numberOfNetworks)
|
||||
{
|
||||
for (int i = 0; i < numberOfNetworks; ++i)
|
||||
{
|
||||
array.add(WiFi.SSID(i));
|
||||
}
|
||||
WiFi.scanDelete();
|
||||
if (WiFi.scanComplete() == WIFI_SCAN_FAILED)
|
||||
{
|
||||
WiFi.scanNetworks(true);
|
||||
}
|
||||
}
|
||||
|
||||
String jsonString;
|
||||
serializeJson(doc, jsonString);
|
||||
request->send(200, "application/json", jsonString);
|
||||
}
|
||||
|
|
|
@ -35,4 +35,6 @@ void onGetConfig(AsyncWebServerRequest *request);
|
|||
|
||||
void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total);
|
||||
|
||||
void onGetNetworks(AsyncWebServerRequest *request);
|
||||
|
||||
// #endif
|
Loading…
Add table
Add a link
Reference in a new issue