Implement silent reboot

This commit is contained in:
jpirnay
2026-05-19 19:38:04 +02:00
parent ffa8ab0911
commit c55a36c702
12 changed files with 150 additions and 81 deletions
@@ -7,6 +7,7 @@
#include <esp_task_wdt.h>
#include "MappedInputManager.h"
#include "SilentRestart.h"
#include "WifiSelectionActivity.h"
#include "activities/network/SignalStrengthWidget.h"
#include "components/UITheme.h"
@@ -54,14 +55,11 @@ void CalibreConnectActivity::onEnter() {
void CalibreConnectActivity::onExit() {
Activity::onExit();
stopWebServer();
MDNS.end();
delay(50);
WiFi.disconnect(false);
delay(30);
WiFi.mode(WIFI_OFF);
delay(30);
if (WiFi.getMode() != WIFI_MODE_NULL) {
WiFi.disconnect(false);
delay(30);
silentRestart();
}
}
void CalibreConnectActivity::onWifiSelectionComplete(const bool connected) {
@@ -3,7 +3,6 @@
#include <DNSServer.h>
#include <ESPmDNS.h>
#include <GfxRenderer.h>
#include <HalClock.h>
#include <I18n.h>
#include <WiFi.h>
#include <esp_task_wdt.h>
@@ -12,6 +11,7 @@
#include "MappedInputManager.h"
#include "NetworkModeSelectionActivity.h"
#include "SilentRestart.h"
#include "WifiSelectionActivity.h"
#include "activities/network/CalibreConnectActivity.h"
#include "activities/network/SignalStrengthWidget.h"
@@ -64,45 +64,17 @@ void CrossPointWebServerActivity::onEnter() {
void CrossPointWebServerActivity::onExit() {
Activity::onExit();
LOG_DBG("WEBACT", "Free heap at onExit start: %d bytes", ESP.getFreeHeap());
state = WebServerActivityState::SHUTTING_DOWN;
// Stop the web server first (before disconnecting WiFi)
stopWebServer();
// Stop mDNS
MDNS.end();
// Stop DNS server if running (AP mode)
if (dnsServer) {
LOG_DBG("WEBACT", "Stopping DNS server...");
dnsServer->stop();
delete dnsServer;
dnsServer = nullptr;
}
// Brief wait for LWIP stack to flush pending packets
delay(50);
// Disconnect WiFi gracefully
if (isApMode) {
LOG_DBG("WEBACT", "Stopping WiFi AP...");
WiFi.softAPdisconnect(true);
// Skip reboot if WiFi was never activated (e.g. user backed out of mode selection).
if (WiFi.getMode() != WIFI_MODE_NULL) {
if (isApMode) {
WiFi.softAPdisconnect(true);
} else {
WiFi.disconnect(false);
}
delay(30);
WiFi.mode(WIFI_OFF);
delay(30);
} else {
HalClock::wifiOff();
}
LOG_DBG("WEBACT", "Free heap at onExit end: %d bytes", ESP.getFreeHeap());
requestUpdate();
if (webServerStarted) {
GUI.drawPopup(renderer, tr(STR_RESTART_DEVICE));
LOG_DBG("WEBACT", "Restarting device after webserver exit to regain heap...");
ESP.restart();
silentRestart();
}
}
@@ -271,15 +243,6 @@ void CrossPointWebServerActivity::startWebServer() {
}
}
void CrossPointWebServerActivity::stopWebServer() {
if (webServer && webServer->isRunning()) {
LOG_DBG("WEBACT", "Stopping web server...");
webServer->stop();
LOG_DBG("WEBACT", "Web server stopped");
}
webServer.reset();
}
void CrossPointWebServerActivity::loop() {
// Handle different states
if (state == WebServerActivityState::SERVER_RUNNING) {
@@ -55,7 +55,6 @@ class CrossPointWebServerActivity final : public Activity {
void onWifiSelectionComplete(bool connected);
void startAccessPoint();
void startWebServer();
void stopWebServer();
public:
explicit CrossPointWebServerActivity(GfxRenderer& renderer, MappedInputManager& mappedInput)