basics of factory reset implemented

This commit is contained in:
Marcus 2024-10-17 02:15:15 +02:00
parent 3f8b060c66
commit 4c57546657
2 changed files with 41 additions and 7 deletions

View file

@ -63,6 +63,9 @@
void setup() { void setup() {
// define output for onboard LED/WIPE pin
pinMode(PinWIPE, OUTPUT);
// Start Serial // Start Serial
Serial.begin(115200); Serial.begin(115200);
@ -75,14 +78,37 @@ void setup() {
Serial.print(CanGrowBuild); Serial.print(CanGrowBuild);
Serial.println(" starting ::."); Serial.println(" starting ::.");
Serial.print(":: To format LittleFS, pull ");
Serial.print(PinWIPE);
Serial.println("(PinWIPE) to LOW - NOW! (2 seconds left) ::");
// blink with the onboard LED on D4 (PinWIPE)
for(byte i = 0; i <= 6 ; i++) {
if(i % 2) {
digitalWrite(PinWIPE, LOW);
} else {
digitalWrite(PinWIPE, HIGH);
}
delay(333);
}
// set back to HIGH because thats the default
digitalWrite(PinWIPE, HIGH);
//delay(2000);
// read status from PinWIPE to WIPE
// when PinWIPE is set to LOW, format LittleFS
if(digitalRead(PinWIPE) == LOW) {
Serial.println("!! formatting LittleFS !!");
LittleFS.format();
}
Serial.println(":: initialise LittleFS ::"); Serial.println(":: initialise LittleFS ::");
if(LittleFS.begin()) { if(LittleFS.begin()) {
Serial.println(":: LittleFS successfully initialized ::"); Serial.println(":: LittleFS successfully initialised ::");
} else { } else {
Serial.println("!! LittleFS failed initializing !!"); Serial.println("!! LittleFS failed initialising !!");
delay(10000);
LittleFS.format();
Serial.println("!! formatting LittleFS !!");
} }
// read the configfile from LittleFS // read the configfile from LittleFS
@ -93,14 +119,14 @@ void setup() {
if(lfs_configfile) { if(lfs_configfile) {
Serial.println(":: LittleFS: config.json successfully created ::"); Serial.println(":: LittleFS: config.json successfully created ::");
// write into the file // write into the file
lfs_configfile.print("{}"); lfs_configfile.print("{test: 2}");
// close the file // close the file
lfs_configfile.close(); lfs_configfile.close();
} }
} else { } else {
Serial.println(":: LittleFS: config.json successfully opened ::"); Serial.println(":: LittleFS: config.json successfully opened ::");
String configfile_content = ""; String configfile_content = "";
Serial.println(lfs_configfile.available());
while (lfs_configfile.available()) { while (lfs_configfile.available()) {
configfile_content += (char)lfs_configfile.read(); configfile_content += (char)lfs_configfile.read();
} }

View file

@ -31,3 +31,11 @@
const char* configfile = "config.json"; const char* configfile = "config.json";
#ifdef ESP8266
const uint8_t PinWIPE = D4;
#endif
#ifdef ESP32
const uint8_t PinWIPE = 2;
#endif