mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 08:49:52 +03:00
show EMS Devices in Web UI - (v2) New Web UI #421
This commit is contained in:
36
src/EMSESPDevicesService.cpp
Normal file
36
src/EMSESPDevicesService.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "EMSESPDevicesService.h"
|
||||
#include "emsesp.h"
|
||||
#include "mqtt.h"
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
EMSESPDevicesService::EMSESPDevicesService(AsyncWebServer * server, SecurityManager * securityManager) {
|
||||
server->on(EMSESP_DEVICES_SERVICE_PATH,
|
||||
HTTP_GET,
|
||||
securityManager->wrapRequest(std::bind(&EMSESPDevicesService::emsespDevicesService, this, std::placeholders::_1),
|
||||
AuthenticationPredicates::IS_AUTHENTICATED));
|
||||
}
|
||||
|
||||
void EMSESPDevicesService::emsespDevicesService(AsyncWebServerRequest * request) {
|
||||
AsyncJsonResponse * response = new AsyncJsonResponse(false, MAX_EMSESP_STATUS_SIZE);
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
JsonArray devices = root.createNestedArray("devices");
|
||||
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
if (emsdevice) {
|
||||
JsonObject deviceRoot = devices.createNestedObject();
|
||||
deviceRoot["type"] = emsdevice->device_type_name();
|
||||
deviceRoot["brand"] = emsdevice->brand_to_string();
|
||||
deviceRoot["name"] = emsdevice->name();
|
||||
deviceRoot["deviceid"] = emsdevice->device_id();
|
||||
deviceRoot["productid"] = emsdevice->product_id();
|
||||
deviceRoot["version"] = emsdevice->version();
|
||||
}
|
||||
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace emsesp
|
||||
31
src/EMSESPDevicesService.h
Normal file
31
src/EMSESPDevicesService.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef EMSESPDevicesService_h
|
||||
#define EMSESPDevicesService_h
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <AsyncJson.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <SecurityManager.h>
|
||||
|
||||
#include <HttpEndpoint.h>
|
||||
#include <MqttPubSub.h>
|
||||
#include <WebSocketTxRx.h>
|
||||
|
||||
#include "EMSESPSettingsService.h"
|
||||
#include "version.h"
|
||||
|
||||
#define MAX_EMSESP_STATUS_SIZE 1024
|
||||
#define EMSESP_DEVICES_SERVICE_PATH "/rest/emsespDevices"
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
class EMSESPDevicesService {
|
||||
public:
|
||||
EMSESPDevicesService(AsyncWebServer * server, SecurityManager * securityManager);
|
||||
|
||||
private:
|
||||
void emsespDevicesService(AsyncWebServerRequest * request);
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "EMSESPStatusService.h"
|
||||
#include "emsesp.h"
|
||||
#include "mqtt.h"
|
||||
#include "version.h"
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
|
||||
@@ -5,14 +5,7 @@
|
||||
#include <AsyncJson.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <SecurityManager.h>
|
||||
|
||||
|
||||
#include <HttpEndpoint.h>
|
||||
#include <MqttPubSub.h>
|
||||
#include <WebSocketTxRx.h>
|
||||
|
||||
#include "EMSESPSettingsService.h"
|
||||
#include "version.h"
|
||||
#include <AsyncMqttClient.h>
|
||||
|
||||
#define MAX_EMSESP_STATUS_SIZE 1024
|
||||
#define EMSESP_STATUS_SERVICE_PATH "/rest/emsespStatus"
|
||||
@@ -24,9 +17,8 @@ class EMSESPStatusService {
|
||||
EMSESPStatusService(AsyncWebServer * server, SecurityManager * securityManager, AsyncMqttClient * mqttClient);
|
||||
|
||||
private:
|
||||
EMSESPSettingsService * _emsespSettingsService;
|
||||
void emsespStatusService(AsyncWebServerRequest * request);
|
||||
AsyncMqttClient * _mqttClient;
|
||||
void emsespStatusService(AsyncWebServerRequest * request);
|
||||
AsyncMqttClient * _mqttClient;
|
||||
|
||||
void init_mqtt();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user