From 933ce71db46cd9de5c3e0aaaebf12cc2654a3959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Mon, 17 Feb 2025 23:22:15 +0100 Subject: [PATCH] restart via http --- src/patrix/Patrix.cpp | 1 + src/patrix/http.cpp | 17 +++++++++++++++++ src/patrix/http.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/src/patrix/Patrix.cpp b/src/patrix/Patrix.cpp index a9fbf26..199f364 100644 --- a/src/patrix/Patrix.cpp +++ b/src/patrix/Patrix.cpp @@ -21,5 +21,6 @@ void loop() { httpSetup(); } patrixLoop(); + httpLoop(); } } diff --git a/src/patrix/http.cpp b/src/patrix/http.cpp index ef5310a..69320ad 100644 --- a/src/patrix/http.cpp +++ b/src/patrix/http.cpp @@ -1,9 +1,12 @@ #include "http.h" +#include "mqtt.h" #include AsyncWebServer server(80); +bool httpDoRestart = false; + void httpNotFound(AsyncWebServerRequest *request) { if (request->method() == HTTP_OPTIONS) { 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() { DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*"); DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "GET, POST, PUT"); DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Content-Type"); + server.on("/restart", httpRestart); server.serveStatic("/", LittleFS, "/http/", "max-age=86400").setDefaultFile("index.html"); server.onNotFound(httpNotFound); server.begin(); } + +void httpLoop() { + if (httpDoRestart) { + Log.info("Restarting..."); + delay(500); + EspClass::restart(); + } +} diff --git a/src/patrix/http.h b/src/patrix/http.h index d24ef36..9225913 100644 --- a/src/patrix/http.h +++ b/src/patrix/http.h @@ -7,4 +7,6 @@ extern AsyncWebServer server; void httpSetup(); +void httpLoop(); + #endif