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:
parent
22d7d2c1f6
commit
e1d7d9511f
@ -555,11 +555,21 @@ void deserializeConfigFromFS() {
|
|||||||
DEBUG_PRINTLN(F("Reading settings from /cfg.json..."));
|
DEBUG_PRINTLN(F("Reading settings from /cfg.json..."));
|
||||||
|
|
||||||
success = readObjectFromFile("/cfg.json", nullptr, &doc);
|
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
|
#ifdef WLED_ADD_EEPROM_SUPPORT
|
||||||
deEEPSettings();
|
deEEPSettings();
|
||||||
#endif
|
#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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,7 +578,7 @@ void deserializeConfigFromFS() {
|
|||||||
bool needsSave = deserializeConfig(doc.as<JsonObject>(), true);
|
bool needsSave = deserializeConfig(doc.as<JsonObject>(), true);
|
||||||
releaseJSONBufferLock();
|
releaseJSONBufferLock();
|
||||||
|
|
||||||
if (needsSave) serializeConfig(); // usermods required new prameters
|
if (needsSave) serializeConfig(); // usermods required new parameters
|
||||||
}
|
}
|
||||||
|
|
||||||
void serializeConfig() {
|
void serializeConfig() {
|
||||||
|
@ -467,11 +467,5 @@ void deEEPSettings() {
|
|||||||
EEPROM.begin(EEPSIZE);
|
EEPROM.begin(EEPSIZE);
|
||||||
loadSettingsFromEEPROM();
|
loadSettingsFromEEPROM();
|
||||||
EEPROM.end();
|
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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user