From 3a29ebd316a5bcf255845a0c96d04bb94978a323 Mon Sep 17 00:00:00 2001 From: Marcus Date: Thu, 17 Oct 2024 01:42:34 +0200 Subject: [PATCH] first steps with LittleFS --- Arduino/CanGrow/CanGrow.ino | 36 ++++++++++++++++++++++++++++++- Arduino/CanGrow/include/CanGrow.h | 3 +++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index f42b4d0..bbfd80e 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -58,7 +58,7 @@ #include // https://github.com/PaulStoffregen/Time #include - +// 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 --"); + } } diff --git a/Arduino/CanGrow/include/CanGrow.h b/Arduino/CanGrow/include/CanGrow.h index beb7853..3c45e53 100644 --- a/Arduino/CanGrow/include/CanGrow.h +++ b/Arduino/CanGrow/include/CanGrow.h @@ -28,3 +28,6 @@ */ #include "CanGrow_Version.h" + + +const char* configfile = "config.json";