Complied V2 version, ready to start testing and start developing GUI
This commit is contained in:
41
lib/Core/Storage.h
Normal file
41
lib/Core/Storage.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef STORAGE_H
|
||||
#define STORAGE_H
|
||||
#include <Arduino.h>
|
||||
#include <LittleFS.h> //Built-in ESP32 library for file system management
|
||||
|
||||
class Storage {
|
||||
public:
|
||||
/**
|
||||
* @brief Initialice LittleFS and read configuration file.
|
||||
* @return String with the JSON content or an empty string if the file does not exist or cannot be read.
|
||||
*/
|
||||
static String readConfigFile() {
|
||||
if(!LittleFS.begin(true)) {
|
||||
Serial.println("[Storage] Error to initialize LittleFS");
|
||||
return "";
|
||||
}
|
||||
if (!LittleFS.exists("/config.json")) {
|
||||
Serial.println("[Storage] Configuration file does not exist");
|
||||
return "";
|
||||
}
|
||||
File file = LittleFS.open("/config.json", "r");
|
||||
if (!file) {
|
||||
Serial.println("[Storage] Error opening configuration file");
|
||||
return "";
|
||||
}
|
||||
String content = file.readString();
|
||||
file.close();
|
||||
return content;
|
||||
}
|
||||
static void saveConfigFile(const String& jsonConfig) {
|
||||
File file = LittleFS.open("/config.json", "w");
|
||||
if (!file) {
|
||||
Serial.println("[Storage] Error opening configuration file for writing");
|
||||
return;
|
||||
}
|
||||
file.print(jsonConfig);
|
||||
file.close();
|
||||
Serial.println("[Storage] Configuration file saved");
|
||||
}
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user