proper reboot

This commit is contained in:
Patrick Haßel 2025-01-10 12:14:02 +01:00
parent 6973677659
commit bec4cc7358
4 changed files with 30 additions and 6 deletions

View File

@ -122,7 +122,12 @@ void httpLoop() {
ws.cleanupClients();
}
void websocketSend(const char *message) {
void httpStop() {
ws.closeAll();
ws.enable(false);
server.end();
}
void websocketSendAll(const char *message) {
if (websocketStarted) {
ws.textAll(message);

View File

@ -5,7 +5,8 @@ void httpSetup();
void httpLoop();
void websocketSend(const char *message);
void httpStop();
void websocketSendAll(const char *message);
#endif

View File

@ -7,6 +7,8 @@
#include "clock.h"
#include "filesystem.h"
#include "http.h"
#include "wifi.h"
void doLog(LogLevel level, const char *format, va_list args);
@ -18,6 +20,8 @@ void logSetup() {
info("Startup");
}
auto rebootRequested = false;
void execute(const char *cmd) {
if (strcmp(cmd, "help") == 0) {
info("HELP");
@ -38,9 +42,7 @@ void execute(const char *cmd) {
info(" %-10s %s", "dns:", WiFi.dnsIP().toString().c_str());
} else if (strcmp(cmd, "reboot") == 0) {
info("REBOOT");
delay(1000);
yield();
ESP.restart();
rebootRequested = true;
} else if (strcmp(cmd, "reconnect") == 0) {
info("RECONNECT");
WiFi.disconnect();
@ -57,7 +59,22 @@ void execute(const char *cmd) {
}
}
void doReboot() {
httpStop();
wifiOff();
LittleFS.end();
yield();
delay(1000);
yield();
ESP.restart();
}
void logLoop() {
if (rebootRequested) {
doReboot();
}
static char buffer[64];
static auto write = buffer;
if (Serial.available() > 0) {

View File

@ -57,6 +57,7 @@ void wifiSetupOTA() {
void wifiOff() {
info("wifi disabled");
wifiEnabled = false;
WiFi.disconnect();
}
void wifiLoop() {
@ -64,7 +65,7 @@ void wifiLoop() {
if (wifiConnected != currentState) {
wifiConnected = currentState;
if (wifiConnected) {
info("wifi connected: %s", WiFi.localIP().toString().c_str());
info("wifi connected as %s", WiFi.localIP().toString().c_str());
wifiSetupOTA();
} else {
warn("wifi disconnected");