restart via http

This commit is contained in:
Patrick Haßel 2025-02-17 23:22:15 +01:00
parent 4ca795501b
commit 933ce71db4
3 changed files with 20 additions and 0 deletions

View File

@ -21,5 +21,6 @@ void loop() {
httpSetup(); httpSetup();
} }
patrixLoop(); patrixLoop();
httpLoop();
} }
} }

View File

@ -1,9 +1,12 @@
#include "http.h" #include "http.h"
#include "mqtt.h"
#include <LittleFS.h> #include <LittleFS.h>
AsyncWebServer server(80); AsyncWebServer server(80);
bool httpDoRestart = false;
void httpNotFound(AsyncWebServerRequest *request) { void httpNotFound(AsyncWebServerRequest *request) {
if (request->method() == HTTP_OPTIONS) { if (request->method() == HTTP_OPTIONS) {
request->send(200); request->send(200);
@ -12,11 +15,25 @@ void httpNotFound(AsyncWebServerRequest *request) {
} }
} }
void httpRestart([[maybe_unused]] AsyncWebServerRequest *request) {
httpDoRestart = true;
request->send(200, "application/json", "true");
}
void httpSetup() { void httpSetup() {
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*"); DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "GET, POST, PUT"); DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "GET, POST, PUT");
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Content-Type"); DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Content-Type");
server.on("/restart", httpRestart);
server.serveStatic("/", LittleFS, "/http/", "max-age=86400").setDefaultFile("index.html"); server.serveStatic("/", LittleFS, "/http/", "max-age=86400").setDefaultFile("index.html");
server.onNotFound(httpNotFound); server.onNotFound(httpNotFound);
server.begin(); server.begin();
} }
void httpLoop() {
if (httpDoRestart) {
Log.info("Restarting...");
delay(500);
EspClass::restart();
}
}

View File

@ -7,4 +7,6 @@ extern AsyncWebServer server;
void httpSetup(); void httpSetup();
void httpLoop();
#endif #endif