mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-07-12 16:35:44 +00:00
moved onGetNetworks function to new file
This commit is contained in:
parent
53e42a0b0b
commit
33bc277bb5
5 changed files with 39 additions and 30 deletions
29
src/routes/networks.cpp
Normal file
29
src/routes/networks.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "networks.h";
|
||||
|
||||
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue