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

* Save config.json with default values on first boot

* Init Ethernet on first boot
pull/2856/head
Christian Schwinne 2022-10-25 17:11:31 +02:00 zatwierdzone przez GitHub
rodzic 22d7d2c1f6
commit e1d7d9511f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 13 dodań i 9 usunięć

Wyświetl plik

@ -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() {

Wyświetl plik

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