From e1d7d9511f2e64a2465dfb53993f61efbaeac9d5 Mon Sep 17 00:00:00 2001 From: Christian Schwinne Date: Tue, 25 Oct 2022 17:11:31 +0200 Subject: [PATCH] Save config.json with default values on initial boot (#2854) * Save config.json with default values on first boot * Init Ethernet on first boot --- wled00/cfg.cpp | 16 +++++++++++++--- wled00/wled_eeprom.cpp | 6 ------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 0f857539..2e9f478f 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -555,11 +555,21 @@ void deserializeConfigFromFS() { DEBUG_PRINTLN(F("Reading settings from /cfg.json...")); success = readObjectFromFile("/cfg.json", nullptr, &doc); - if (!success) { //if file does not exist, try reading from EEPROM + if (!success) { // if file does not exist, optionally try reading from EEPROM and then save defaults to FS + releaseJSONBufferLock(); #ifdef WLED_ADD_EEPROM_SUPPORT deEEPSettings(); #endif - releaseJSONBufferLock(); + + // save default values to /cfg.json + // call readFromConfig() with an empty object so that usermods can initialize to defaults prior to saving + JsonObject empty = JsonObject(); + usermods.readFromConfig(empty); + serializeConfig(); + // init Ethernet (in case default type is set at compile time) + #ifdef WLED_USE_ETHERNET + WLED::instance().initEthernet(); + #endif return; } @@ -568,7 +578,7 @@ void deserializeConfigFromFS() { bool needsSave = deserializeConfig(doc.as(), true); releaseJSONBufferLock(); - if (needsSave) serializeConfig(); // usermods required new prameters + if (needsSave) serializeConfig(); // usermods required new parameters } void serializeConfig() { diff --git a/wled00/wled_eeprom.cpp b/wled00/wled_eeprom.cpp index 5e56a8b0..0b9e7642 100644 --- a/wled00/wled_eeprom.cpp +++ b/wled00/wled_eeprom.cpp @@ -467,11 +467,5 @@ void deEEPSettings() { EEPROM.begin(EEPSIZE); loadSettingsFromEEPROM(); EEPROM.end(); - - //call readFromConfig() with an empty object so that usermods can initialize to defaults prior to saving - JsonObject empty = JsonObject(); - usermods.readFromConfig(empty); - - serializeConfig(); } #endif