Skip to content
4 changes: 2 additions & 2 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ void deserializeConfigFromFS() {
DEBUG_PRINTLN(F("Reading settings from /cfg.json..."));

success = readObjectFromFile("/cfg.json", nullptr, &doc);
if (!success) { // if file does not exist, optionally try reading from EEPROM and then save defaults to FS
if (!success || doc.size() == 0) { // if file does not exist or contains only empty JSON (e.g. "{}"), try reading from EEPROM (if supported) and then save defaults to FS
releaseJSONBufferLock();
#ifdef WLED_ADD_EEPROM_SUPPORT
deEEPSettings();
Expand Down Expand Up @@ -1122,7 +1122,7 @@ bool deserializeConfigSec() {
if (!requestJSONBufferLock(3)) return false;

bool success = readObjectFromFile("/wsec.json", nullptr, &doc);
if (!success) {
if (!success || doc.size() == 0) { // treat empty JSON (e.g. "{}") the same as a missing file
releaseJSONBufferLock();
return false;
}
Expand Down
10 changes: 9 additions & 1 deletion wled00/presets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,15 @@ bool getPresetName(byte index, String& name)

void initPresetsFile()
{
if (WLED_FS.exists(getFileName())) return;
if (WLED_FS.exists(getFileName())) {
// treat an empty JSON file (e.g. "{}") the same as a missing file:
// f.size() < 3 is the same threshold used in appendObjectToFile() to detect an uninitialized file
File f = WLED_FS.open(getFileName(), "r");
bool empty = f && f.size() < 3;
Comment thread
softhack007 marked this conversation as resolved.
Outdated
if (f) f.close();
if (!empty) return;
WLED_FS.remove(getFileName()); // remove the empty file so it can be recreated below
}

StaticJsonDocument<64> doc;
JsonObject sObj = doc.to<JsonObject>();
Expand Down
Loading