From 9fb424fd685cde073e36868f81f8ff0ca5423208 Mon Sep 17 00:00:00 2001 From: "Adrian A. Baumann" Date: Wed, 24 Jun 2026 00:10:38 +0200 Subject: [PATCH] Update factory reset procedure in README and main.cpp for clarity and functionality --- README.md | 11 +++++++---- src/main.cpp | 33 ++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 42c839e..337a590 100644 --- a/README.md +++ b/README.md @@ -79,12 +79,15 @@ After connecting, the device is reachable at: ### Factory reset (forgot password) -If you lose the web UI password, hold the **BOOT button** (GPIO0) for 3 seconds during startup. The firmware resets all settings to factory defaults **except** meter pin assignments and calibration (maxDuty), which are preserved. On acknowledgement, all connected meters sweep 0→100→0. +If you lose the web UI password, **reset the device 5 times in quick succession** (press the EN button or cycle power 5× within a few seconds — before the boot completes). The firmware resets all settings to factory defaults **except** meter pin assignments and calibration (maxDuty), which are preserved. On acknowledgement, all connected meters sweep 0→100→0. -Serial output confirms the reset: +Serial output shows the progress: ``` -[BOOT] BOOT button held, hold 3s for factory reset... +[BOOT] reset count 1/5 +[BOOT] reset count 2/5 +... +[BOOT] reset count 5/5, triggering factory reset [BOOT] factory reset triggered! ... [BOOT] factory reset complete, restarting... @@ -236,4 +239,4 @@ Config is stored as JSON in LittleFS at `/config.json`. } ``` -The file is written by the web UI and should not need manual editing. To reset to factory defaults (keeping pin/calibration), hold the BOOT button for 3 seconds at startup. To erase everything including flash, use `pio run --target erase`. +The file is written by the web UI and should not need manual editing. To reset to factory defaults (keeping pin/calibration), reset the device 5 times in quick succession. To erase everything including flash, use `pio run --target erase`. diff --git a/src/main.cpp b/src/main.cpp index da3d82d..7dd5251 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -613,7 +613,7 @@ static void startServer() { } // --------------------------------------------------------------------------- -// Factory reset (hold BOOT button 3s at startup) +// Factory reset (rapid reset 5× within a few seconds) // --------------------------------------------------------------------------- static void factoryReset() { @@ -699,19 +699,25 @@ static void factoryReset() { } static void checkFactoryReset() { - pinMode(0, INPUT_PULLUP); - delay(10); - if (digitalRead(0) == LOW) { - Serial.println("[BOOT] BOOT button held, hold 3s for factory reset..."); - unsigned long start = millis(); - while (millis() - start < 3000) { - delay(50); - if (digitalRead(0) != LOW) { - Serial.println("[BOOT] factory reset aborted (button released)"); - return; - } - } + const int THRESHOLD = 5; + int count = 0; + File f = LittleFS.open("/reset_count", "r"); + if (f) { + count = f.parseInt(); + f.close(); + } + count++; + if (count >= THRESHOLD) { + LittleFS.remove("/reset_count"); + Serial.printf("[BOOT] reset count %d, triggering factory reset\n", count); factoryReset(); + return; + } + f = LittleFS.open("/reset_count", "w"); + if (f) { + f.print(count); + f.close(); + Serial.printf("[BOOT] reset count %d/%d\n", count, THRESHOLD); } } @@ -754,6 +760,7 @@ void setup() { startMDNS(); mqttReconnectAt = 0; + LittleFS.remove("/reset_count"); Serial.printf("[BOOT] ready at http://%s.local or http://%s\n", hostname, WiFi.localIP().toString().c_str()); }