restart via http
This commit is contained in:
parent
4ca795501b
commit
933ce71db4
@ -21,5 +21,6 @@ void loop() {
|
||||
httpSetup();
|
||||
}
|
||||
patrixLoop();
|
||||
httpLoop();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
#include "http.h"
|
||||
#include "mqtt.h"
|
||||
|
||||
#include <LittleFS.h>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,4 +7,6 @@ extern AsyncWebServer server;
|
||||
|
||||
void httpSetup();
|
||||
|
||||
void httpLoop();
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user