feat: two-tier factory reset, WiFi fallback chain, SettingsWebServer

Factory reset (F-015):
- InputManager gains MEDIUM_PRESSED state with mediumPressMs=5000
- 5s hold: wipe WiFi credentials only, restart on release
- 10s hold: full factory reset (WiFi wipe already done at 5s mark)
- New callbacks: setFactoryResetMediumPressCallback,
  setFactoryResetMediumPressReleaseCallback

WiFi fallback chain (F-016):
- Connection now cycles: saved creds → hardcoded failsafe → portal
- MAX_WIFI_FAILURES reduced 3→2 per stage
- Portal now reboots after saving credentials (fixes port 80 conflict
  between WiFiManager and AsyncWebServer)
- AP SSID sourced from netConfig.apSsid instead of hardcoded pattern
- clearWiFiCredentials() added to Networking for 5s reset gesture

SettingsWebServer (F-017):
- Instantiated in main.cpp alongside CommunicationRouter
- begin() called when network becomes ready (both WiFi paths)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-30 09:52:17 +03:00
co-authored by Claude Sonnet 4.6
parent ee73d4d2c4
commit df8426fce6
5 changed files with 183 additions and 124 deletions
+24 -4
View File
@@ -126,6 +126,7 @@
#include "HealthMonitor/HealthMonitor.hpp"
#include "FirmwareValidator/FirmwareValidator.hpp"
#include "InputManager/InputManager.hpp"
#include "SettingsWebServer/SettingsWebServer.hpp"
#include "Version.hpp"
#include "NvsMigration/NvsMigration.hpp"
#if HAS_RF
@@ -150,6 +151,7 @@ AsyncWebSocket ws("/ws");
AsyncUDP udp;
Networking networking(configManager);
CommunicationRouter communication(configManager, otaManager, networking, server, ws, udp);
SettingsWebServer settingsWebServer(server, configManager, networking);
HealthMonitor healthMonitor;
FirmwareValidator firmwareValidator;
InputManager inputManager;
@@ -422,11 +424,25 @@ static void bootOtaCheck() {
Serial.println("[BootOTA] All servers failed during flash — continuing normal boot");
}
// Called at 5s hold: wipe WiFi credentials only (restart triggered on release)
void handleWiFiCredsReset() {
LOG_WARNING(TAG, "Factory Reset: WiFi credentials cleared (5s press)");
networking.clearWiFiCredentials();
}
// Called on release after 5s but before 10s: restart after WiFi wipe
void handleWiFiCredsResetRelease() {
LOG_WARNING(TAG, "Factory Reset: Restarting after WiFi credentials wipe");
delay(1000);
ESP.restart();
}
// Called at 10s hold: WiFi creds were already cleared at 5s, now clear all settings too
void handleFactoryReset() {
if (configManager.resetAllToDefaults()) {
delay(3000);
ESP.restart();
}
LOG_WARNING(TAG, "Factory Reset: Full reset triggered (10s press)");
configManager.resetAllToDefaults();
delay(1000);
ESP.restart();
}
#if HAS_RTC
@@ -491,6 +507,8 @@ void setup()
LOG_INFO(TAG, "Log level set to %d from configuration", logLevel);
inputManager.begin();
inputManager.setFactoryResetMediumPressCallback(handleWiFiCredsReset);
inputManager.setFactoryResetMediumPressReleaseCallback(handleWiFiCredsResetRelease);
inputManager.setFactoryResetLongPressCallback(handleFactoryReset);
// ═══════════════════════════════════════════════════════════════════════════════
@@ -663,6 +681,7 @@ void setup()
// Start AsyncWebServer when network becomes available (only once!)
if (!webServerStarted && networking.getState() != NetworkState::WIFI_PORTAL_MODE) {
settingsWebServer.begin();
LOG_INFO(TAG, "🚀 Starting AsyncWebServer on port 80...");
server.begin();
LOG_INFO(TAG, "✅ AsyncWebServer started on http://%s", networking.getLocalIP().c_str());
@@ -689,6 +708,7 @@ void setup()
// 🔥 CRITICAL: Start AsyncWebServer ONLY when network is ready
// Do NOT start if WiFiManager portal is active (port 80 conflict!)
if (!webServerStarted && networking.getState() != NetworkState::WIFI_PORTAL_MODE) {
settingsWebServer.begin();
LOG_INFO(TAG, "🚀 Starting AsyncWebServer on port 80...");
server.begin();
LOG_INFO(TAG, "✅ AsyncWebServer started on http://%s", networking.getLocalIP().c_str());