feat: send beacon and reboot buttons

This commit is contained in:
SQ2CPA
2024-03-19 17:02:42 +01:00
parent 67e1c528f3
commit 5337cb2d46
5 changed files with 66 additions and 9 deletions
+17
View File
@@ -3,6 +3,7 @@
#include "web_utils.h"
extern Configuration Config;
extern uint32_t lastBeaconTx;
extern const char web_index_html[] asm("_binary_data_embed_index_html_gz_start");
extern const char web_index_html_end[] asm("_binary_data_embed_index_html_gz_end");
@@ -163,6 +164,21 @@ namespace WEB_Utils {
ESP.restart();
}
void handleAction(AsyncWebServerRequest *request) {
String type = request->getParam("type", false)->value();
if (type == "send-beacon") {
Serial.println(lastBeaconTx);
lastBeaconTx = 0;
request->send(200, "text/plain", "Beacon will be sent in a while");
} else if (type == "reboot") {
ESP.restart();
} else {
request->send(404, "text/plain", "Not Found");
}
}
void handleStyle(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/css", (const uint8_t*)web_style_css, web_style_css_len);
response->addHeader("Content-Encoding", "gzip");
@@ -194,6 +210,7 @@ namespace WEB_Utils {
server.on("/status", HTTP_GET, handleStatus);
server.on("/configuration.json", HTTP_GET, handleReadConfiguration);
server.on("/configuration.json", HTTP_POST, handleWriteConfiguration);
server.on("/action", HTTP_POST, handleAction);
server.on("/style.css", HTTP_GET, handleStyle);
server.on("/script.js", HTTP_GET, handleScript);
server.on("/bootstrap.css", HTTP_GET, handleBootstrapStyle);