Factory reset: 5x clears config, 10x also clears WiFi credentials
This commit is contained in:
+14
-7
@@ -392,11 +392,11 @@ static void startServer() {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Factory reset (rapid reset 5x within a few seconds)
|
||||
// Factory reset (5x = config only, 10x = config + WiFi credentials)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static void factoryReset() {
|
||||
Serial.println("[BOOT] factory reset triggered!");
|
||||
static void factoryReset(bool clearWifi) {
|
||||
Serial.printf("[BOOT] factory reset triggered (clearWifi=%d)!\n", clearWifi);
|
||||
|
||||
strlcpy(hostname, HOSTNAME_DEFAULT, sizeof(hostname));
|
||||
hostnameParam.setValue(hostname, strlen(hostname));
|
||||
@@ -413,13 +413,20 @@ static void factoryReset() {
|
||||
|
||||
saveConfig();
|
||||
|
||||
if (clearWifi) {
|
||||
WiFiManager wm;
|
||||
wm.resetSettings();
|
||||
Serial.println("[BOOT] WiFi credentials erased");
|
||||
}
|
||||
|
||||
Serial.println("[BOOT] factory reset complete, restarting...");
|
||||
delay(200);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
static void checkFactoryReset() {
|
||||
const int THRESHOLD = 5;
|
||||
const int THRESHOLD_CONFIG = 5;
|
||||
const int THRESHOLD_WIFI = 10;
|
||||
int count = 0;
|
||||
File f = LittleFS.open("/reset_count", "r");
|
||||
if (f) {
|
||||
@@ -427,17 +434,17 @@ static void checkFactoryReset() {
|
||||
f.close();
|
||||
}
|
||||
count++;
|
||||
if (count >= THRESHOLD) {
|
||||
if (count >= THRESHOLD_CONFIG) {
|
||||
LittleFS.remove("/reset_count");
|
||||
Serial.printf("[BOOT] reset count %d, triggering factory reset\n", count);
|
||||
factoryReset();
|
||||
factoryReset(count >= THRESHOLD_WIFI);
|
||||
return;
|
||||
}
|
||||
f = LittleFS.open("/reset_count", "w");
|
||||
if (f) {
|
||||
f.print(count);
|
||||
f.close();
|
||||
Serial.printf("[BOOT] reset count %d/%d\n", count, THRESHOLD);
|
||||
Serial.printf("[BOOT] reset count %d/%d\n", count, THRESHOLD_CONFIG);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user