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() {
|
static void factoryReset(bool clearWifi) {
|
||||||
Serial.println("[BOOT] factory reset triggered!");
|
Serial.printf("[BOOT] factory reset triggered (clearWifi=%d)!\n", clearWifi);
|
||||||
|
|
||||||
strlcpy(hostname, HOSTNAME_DEFAULT, sizeof(hostname));
|
strlcpy(hostname, HOSTNAME_DEFAULT, sizeof(hostname));
|
||||||
hostnameParam.setValue(hostname, strlen(hostname));
|
hostnameParam.setValue(hostname, strlen(hostname));
|
||||||
@@ -413,13 +413,20 @@ static void factoryReset() {
|
|||||||
|
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
|
||||||
|
if (clearWifi) {
|
||||||
|
WiFiManager wm;
|
||||||
|
wm.resetSettings();
|
||||||
|
Serial.println("[BOOT] WiFi credentials erased");
|
||||||
|
}
|
||||||
|
|
||||||
Serial.println("[BOOT] factory reset complete, restarting...");
|
Serial.println("[BOOT] factory reset complete, restarting...");
|
||||||
delay(200);
|
delay(200);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkFactoryReset() {
|
static void checkFactoryReset() {
|
||||||
const int THRESHOLD = 5;
|
const int THRESHOLD_CONFIG = 5;
|
||||||
|
const int THRESHOLD_WIFI = 10;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
File f = LittleFS.open("/reset_count", "r");
|
File f = LittleFS.open("/reset_count", "r");
|
||||||
if (f) {
|
if (f) {
|
||||||
@@ -427,17 +434,17 @@ static void checkFactoryReset() {
|
|||||||
f.close();
|
f.close();
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
if (count >= THRESHOLD) {
|
if (count >= THRESHOLD_CONFIG) {
|
||||||
LittleFS.remove("/reset_count");
|
LittleFS.remove("/reset_count");
|
||||||
Serial.printf("[BOOT] reset count %d, triggering factory reset\n", count);
|
Serial.printf("[BOOT] reset count %d, triggering factory reset\n", count);
|
||||||
factoryReset();
|
factoryReset(count >= THRESHOLD_WIFI);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
f = LittleFS.open("/reset_count", "w");
|
f = LittleFS.open("/reset_count", "w");
|
||||||
if (f) {
|
if (f) {
|
||||||
f.print(count);
|
f.print(count);
|
||||||
f.close();
|
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