add support for web server
This commit is contained in:
parent
10721cfe52
commit
9fa610c7bf
@ -113,6 +113,8 @@ struct EasyHomeSwitch : Switch {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto switchHomebox = new PollinSwitch{"00011", 4, "homebox"};
|
||||||
|
|
||||||
Command* commands[] = {
|
Command* commands[] = {
|
||||||
HaESP::restartButton()
|
HaESP::restartButton()
|
||||||
.asDevice(gatewayDevice)
|
.asDevice(gatewayDevice)
|
||||||
@ -140,7 +142,7 @@ Command* commands[] = {
|
|||||||
new PollinSwitch{"00001", 2, "Fire Tv", "Living room"},
|
new PollinSwitch{"00001", 2, "Fire Tv", "Living room"},
|
||||||
new PollinSwitch{"00001", 3, "Diningroom player", "Dining room"},
|
new PollinSwitch{"00001", 3, "Diningroom player", "Dining room"},
|
||||||
new PollinSwitch{"00001", 4},
|
new PollinSwitch{"00001", 4},
|
||||||
new PollinSwitch{"00011", 4, "homebox"},
|
switchHomebox,
|
||||||
new PollinSwitch{"11111", 4, "Train", "Playroom"}
|
new PollinSwitch{"11111", 4, "Train", "Playroom"}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@ Scheduler ts;
|
|||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
#include "ota.h"
|
#include "ota.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
|
#include "webserver.h"
|
||||||
|
|
||||||
namespace Board {
|
namespace Board {
|
||||||
|
|
||||||
@ -46,10 +47,12 @@ namespace Board {
|
|||||||
[] {
|
[] {
|
||||||
Ota::tLoop.enable();
|
Ota::tLoop.enable();
|
||||||
Mqtt::tReConnect.enable();
|
Mqtt::tReConnect.enable();
|
||||||
|
WebServer::setup();
|
||||||
},
|
},
|
||||||
[] {
|
[] {
|
||||||
Ota::tLoop.disable();
|
Ota::tLoop.disable();
|
||||||
Mqtt::tReConnect.disable();
|
Mqtt::tReConnect.disable();
|
||||||
|
WebServer::stop();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Ota::setup(
|
Ota::setup(
|
||||||
|
|||||||
45
gateway/include/webserver.h
Normal file
45
gateway/include/webserver.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -35,6 +35,7 @@ lib_deps =
|
|||||||
arkhipenko/TaskScheduler@^3.8.5
|
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.7.0
|
||||||
https://git.hodos.ro/libraries/wifi.git@^2.0.0
|
https://git.hodos.ro/libraries/wifi.git@^2.0.0
|
||||||
|
esphome/ESPAsyncWebServer-esphome@^3.4.0
|
||||||
upload_port = 192.168.6.161
|
upload_port = 192.168.6.161
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_flags =
|
upload_flags =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user