Save config.json with default values on initial boot (#2854)

* Save config.json with default values on first boot

* Init Ethernet on first boot
This commit is contained in:
Christian Schwinne 2022-10-25 17:11:31 +02:00 committed by GitHub
parent 22d7d2c1f6
commit e1d7d9511f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

@ -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<JsonObject>(), true);
releaseJSONBufferLock();
if (needsSave) serializeConfig(); // usermods required new prameters
if (needsSave) serializeConfig(); // usermods required new parameters
}
void serializeConfig() {

View File

@ -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