use web server from library

This commit is contained in:
Nicu Hodos 2025-09-06 22:05:47 +02:00
parent 9fa610c7bf
commit e80b4090e6
4 changed files with 4 additions and 49 deletions

View File

@ -113,8 +113,6 @@ struct EasyHomeSwitch : Switch {
}
};
auto switchHomebox = new PollinSwitch{"00011", 4, "homebox"};
Command* commands[] = {
HaESP::restartButton()
.asDevice(gatewayDevice)
@ -142,7 +140,7 @@ Command* commands[] = {
new PollinSwitch{"00001", 2, "Fire Tv", "Living room"},
new PollinSwitch{"00001", 3, "Diningroom player", "Dining room"},
new PollinSwitch{"00001", 4},
switchHomebox,
new PollinSwitch{"00011", 4, "homebox"},
new PollinSwitch{"11111", 4, "Train", "Playroom"}
};

View File

@ -60,6 +60,7 @@ namespace Board {
Mqtt::publishCleanupConfig();
delay(2000);
Mqtt::disconnect();
WebServer::stop();
});
tReadCommand.enable();

View File

@ -1,45 +0,0 @@
#ifdef ESP32
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESPAsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>
#include "devices.h"
AsyncWebServer server(80);
namespace WebServer {
void notFound(AsyncWebServerRequest *request) {
request->send(404, "text/plain", "Not found");
}
void setup() {
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", "Hello, world");
});
server.on("/switch/homebox", HTTP_GET, [](AsyncWebServerRequest *request) {
if (request->hasParam("state")) {
AsyncWebParameter* switchState = request->getParam("state");
switchHomebox->onCommand(switchState->value().c_str());
request->send(200, "text/plain", switchState->value().c_str());
} else {
request->send(200, "text/plain", "No parameters provided");
}
});
server.on("/restart", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain");
ESP.restart();
});
server.onNotFound(notFound);
server.begin();
}
void stop() {
server.end();
}
}

View File

@ -33,7 +33,8 @@ framework = arduino
lib_deps =
${env.lib_deps}
arkhipenko/TaskScheduler@^3.8.5
https://git.hodos.ro/libraries/ha-mqtt.git@^1.7.0
https://git.hodos.ro/libraries/ha-mqtt.git@^1.8.0
https://git.hodos.ro/libraries/ha-webserver.git@^0.1.0
https://git.hodos.ro/libraries/wifi.git@^2.0.0
esphome/ESPAsyncWebServer-esphome@^3.4.0
upload_port = 192.168.6.161