mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-24 14:57:16 +00:00
Add support for Last Known Good Settings
This commit is contained in:
parent
861c76baca
commit
a21acebdb4
@ -540,7 +540,7 @@ void SettingsSave(uint8_t rotate)
|
||||
#ifdef ESP8266
|
||||
#ifdef USE_UFILESYS
|
||||
TfsSaveFile(TASM_FILE_SETTINGS, (const uint8_t*)&Settings, sizeof(Settings));
|
||||
#endif
|
||||
#endif // USE_UFILESYS
|
||||
if (ESP.flashEraseSector(settings_location)) {
|
||||
ESP.flashWrite(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(Settings));
|
||||
}
|
||||
@ -578,7 +578,7 @@ void SettingsLoad(void) {
|
||||
flash_location = 1;
|
||||
slot = 0;
|
||||
}
|
||||
#endif
|
||||
#endif // USE_UFILESYS
|
||||
while (slot <= max_slots) { // Read all config pages in search of valid and latest
|
||||
if (slot > 0) {
|
||||
flash_location = (1 == slot) ? FLASH_EEPROM_START : (2 == slot) ? SETTINGS_LOCATION : flash_location -1;
|
||||
@ -602,7 +602,7 @@ void SettingsLoad(void) {
|
||||
TfsLoadFile(TASM_FILE_SETTINGS, (uint8_t*)&Settings, sizeof(Settings));
|
||||
AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG "Loaded from File, " D_COUNT " %lu"), Settings.save_flag);
|
||||
} else
|
||||
#endif
|
||||
#endif // USE_UFILESYS
|
||||
{
|
||||
ESP.flashRead(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(Settings));
|
||||
AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG D_LOADED_FROM_FLASH_AT " %X, " D_COUNT " %lu"), settings_location, Settings.save_flag);
|
||||
@ -617,7 +617,15 @@ void SettingsLoad(void) {
|
||||
|
||||
#ifndef FIRMWARE_MINIMAL
|
||||
if ((0 == settings_location) || (Settings.cfg_holder != (uint16_t)CFG_HOLDER)) { // Init defaults if cfg_holder differs from user settings in my_user_config.h
|
||||
SettingsDefault();
|
||||
#ifdef USE_UFILESYS
|
||||
if (TfsLoadFile(TASM_FILE_SETTINGS_LKG, (uint8_t*)&Settings, sizeof(Settings)) && (Settings.cfg_crc32 == GetSettingsCrc32())) {
|
||||
settings_location = 1;
|
||||
AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG "Loaded from LKG File, " D_COUNT " %lu"), Settings.save_flag);
|
||||
} else
|
||||
#endif // USE_UFILESYS
|
||||
{
|
||||
SettingsDefault();
|
||||
}
|
||||
}
|
||||
settings_crc32 = GetSettingsCrc32();
|
||||
#endif // FIRMWARE_MINIMAL
|
||||
|
@ -886,6 +886,15 @@ void PerformEverySecond(void)
|
||||
ESP_getSketchSize(); // Init sketchsize as it can take up to 2 seconds
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_UFILESYS
|
||||
static bool settings_lkg = false; // Settings saved as Last Known Good
|
||||
// Copy Settings as Last Known Good if no changes have been saved since 30 minutes
|
||||
if (!settings_lkg && (UtcTime() > START_VALID_TIME) && (Settings.cfg_timestamp < UtcTime() - (30 * 60))) {
|
||||
TfsSaveFile(TASM_FILE_SETTINGS_LKG, (const uint8_t*)&Settings, sizeof(Settings));
|
||||
settings_lkg = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------*\
|
||||
|
@ -225,8 +225,9 @@ const uint16_t LOG_BUFFER_SIZE = 4000; // Max number of characters in lo
|
||||
#error "Arduino ESP8266 Core versions before 2.7.1 are not supported"
|
||||
#endif
|
||||
|
||||
#define TASM_FILE_SETTINGS "/.settings"
|
||||
#define TASM_FILE_ZIGBEE "/zb"
|
||||
#define TASM_FILE_SETTINGS "/.settings" // Settings binary blob
|
||||
#define TASM_FILE_SETTINGS_LKG "/.settings.lkg" // Last Known Good Settings binary blob
|
||||
#define TASM_FILE_ZIGBEE "/zb" // Zigbee settings blob as used by CC2530 on ESP32
|
||||
|
||||
#ifndef MQTT_MAX_PACKET_SIZE
|
||||
#define MQTT_MAX_PACKET_SIZE 1200 // Bytes
|
||||
|
Loading…
x
Reference in New Issue
Block a user