mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-05-19 10:32:56 +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
|
@ -16,6 +16,7 @@
|
||||||
#include "ESPDMX.h"
|
#include "ESPDMX.h"
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
#include "routes/config.h"
|
#include "routes/config.h"
|
||||||
|
#include "routes/networks.h"
|
||||||
#include "routes/status.h"
|
#include "routes/status.h"
|
||||||
|
|
||||||
DMXESPSerial dmx1;
|
DMXESPSerial dmx1;
|
||||||
|
|
|
@ -161,31 +161,3 @@ void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size
|
||||||
request->send(400, "text/plain", e.what());
|
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);
|
|
||||||
}
|
|
||||||
|
|
|
@ -48,6 +48,4 @@ void onGetConfig(AsyncWebServerRequest *request);
|
||||||
|
|
||||||
void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total);
|
void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total);
|
||||||
|
|
||||||
void onGetNetworks(AsyncWebServerRequest *request);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
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);
|
||||||
|
}
|
9
src/routes/networks.h
Normal file
9
src/routes/networks.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#include <AsyncWebServer_ESP32_W5500.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
#ifndef NETWORKS_H
|
||||||
|
#define NETWORKS_H
|
||||||
|
|
||||||
|
void onGetNetworks(AsyncWebServerRequest *request);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Reference in a new issue