configmanager bugfix

This commit is contained in:
Klaus K Wilting 2020-10-05 15:41:49 +02:00
parent b28a86c9a2
commit d530187130

View File

@ -63,7 +63,9 @@ static void defaultConfig(configData_t *myconfig) {
// migrate runtime configuration from earlier to current version // migrate runtime configuration from earlier to current version
static void migrateConfig(void) { static void migrateConfig(void) {
// currently no configuration migration rules are implemented // currently no configuration migration rules are implemented, we reset to
// factory settings instead
eraseConfig();
} }
// save current configuration from RAM to NVRAM // save current configuration from RAM to NVRAM
@ -99,24 +101,23 @@ bool loadConfig() {
if (!nvram.begin(DEVCONFIG, true)) { if (!nvram.begin(DEVCONFIG, true)) {
ESP_LOGI(TAG, "NVRAM initialized, device starts with factory settings"); ESP_LOGI(TAG, "NVRAM initialized, device starts with factory settings");
eraseConfig(); eraseConfig();
return true;
} }
// simple check that runtime config data matches // simple check that runtime config data matches
if (nvram.getBytesLength(DEVCONFIG) != (cfgLen + cfgLen2)) { // if (nvram.getBytesLength(DEVCONFIG) != (cfgLen + cfgLen2)) {
ESP_LOGE(TAG, "Configuration invalid"); // ESP_LOGE(TAG, "Configuration invalid");
return false; // return false;
} //}
// load device runtime config from nvram and copy it to byte array // load device runtime config from nvram and copy it to byte array
nvram.getBytes(DEVCONFIG, buffer, cfgLen + cfgLen2); nvram.getBytes(DEVCONFIG, buffer, cfgLen + cfgLen2);
nvram.end(); nvram.end();
// validate loaded configuration by checking magic bytes at end of array // validate loaded configuration by checking magic bytes at end of array
if (memcmp(buffer + cfgLen, &cfgMagicBytes, cfgLen2) != 0) { // if (memcmp(buffer + cfgLen, &cfgMagicBytes, cfgLen2) != 0) {
ESP_LOGW(TAG, "No configuration found"); // ESP_LOGW(TAG, "No configuration found");
return false; // return false;
} //}
// copy loaded configuration into runtime cfg struct // copy loaded configuration into runtime cfg struct
memcpy(&cfg, buffer, cfgLen); memcpy(&cfg, buffer, cfgLen);