first steps with LittleFS
This commit is contained in:
parent
11b7217f57
commit
3a29ebd316
2 changed files with 38 additions and 1 deletions
|
@ -58,7 +58,7 @@
|
|||
#include <ArduinoJson.h>
|
||||
// https://github.com/PaulStoffregen/Time
|
||||
#include <TimeLib.h>
|
||||
|
||||
// arduino-core for esp8266 and esp32
|
||||
#include "LittleFS.h"
|
||||
|
||||
|
||||
|
@ -75,6 +75,40 @@ void setup() {
|
|||
Serial.print(CanGrowBuild);
|
||||
Serial.println(" starting ::.");
|
||||
|
||||
Serial.println(":: initialise LittleFS ::");
|
||||
if(LittleFS.begin()) {
|
||||
Serial.println(":: LittleFS successfully initialized ::");
|
||||
} else {
|
||||
Serial.println("!! LittleFS failed initializing !!");
|
||||
delay(10000);
|
||||
LittleFS.format();
|
||||
Serial.println("!! formatting LittleFS !!");
|
||||
}
|
||||
|
||||
// read the configfile from LittleFS
|
||||
File lfs_configfile = LittleFS.open(configfile, "r");
|
||||
if(!lfs_configfile) {
|
||||
Serial.println("!! LittleFS: config.json not found, creating it !!");
|
||||
lfs_configfile = LittleFS.open(configfile, "w");
|
||||
if(lfs_configfile) {
|
||||
Serial.println(":: LittleFS: config.json successfully created ::");
|
||||
// write into the file
|
||||
lfs_configfile.print("{}");
|
||||
// close the file
|
||||
lfs_configfile.close();
|
||||
}
|
||||
} else {
|
||||
Serial.println(":: LittleFS: config.json successfully opened ::");
|
||||
String configfile_content = "";
|
||||
Serial.println(lfs_configfile.available());
|
||||
while (lfs_configfile.available()) {
|
||||
configfile_content += (char)lfs_configfile.read();
|
||||
}
|
||||
|
||||
Serial.println("-- LittleFS: config.json content --");
|
||||
Serial.println(configfile_content);
|
||||
Serial.println("-- LittleFS: config.json end --");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -28,3 +28,6 @@
|
|||
*/
|
||||
|
||||
#include "CanGrow_Version.h"
|
||||
|
||||
|
||||
const char* configfile = "config.json";
|
||||
|
|
Loading…
Reference in a new issue