diff --git a/src/FSPersistence.h b/src/FSPersistence.h index f3d9573c..427a6176 100644 --- a/src/FSPersistence.h +++ b/src/FSPersistence.h @@ -3,6 +3,7 @@ #include #include +#include template class FSPersistence { @@ -51,13 +52,33 @@ class FSPersistence { JsonObject jsonObject = jsonDocument.to(); _statefulService->read(jsonObject, _stateReader); + if(!_fs->exists(FS_CONFIG_DIRECTORY)){ + Serial.println(F("Directory doesn't exists.")); + + if(_fs->mkdir(FS_CONFIG_DIRECTORY)){ + Serial.println(F("Directory created.")); + } + else{ + Serial.println(F("Can't create the directory.")); + } + } + else{ + Serial.println(F("Directory exists.")); + } + // serialize it to filesystem File settingsFile = _fs->open(_filePath, "w"); // failed to open file, return false if (!settingsFile) { + Serial.print(F("Can't open the file: ")); + Serial.println(_filePath); return false; } + else{ + Serial.print(_filePath); + Serial.println(F(" was opened.")); + } // serialize the data to the file serializeJson(jsonDocument, settingsFile);