diff --git a/CHANGELOG.md b/CHANGELOG.md index f20871523..8f6c5c877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ All notable changes to this project will be documented in this file. ### Changed - File editor no-wrap (#13427) +### Fixed +- Initial reset RTC memory based variables like EnergyToday and EnergyTotal + ## [Released] ## [10.0.0] 20211019 diff --git a/RELEASENOTES.md b/RELEASENOTES.md index e910d302f..98e13c6a1 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -108,3 +108,4 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo - File editor no-wrap [#13427](https://github.com/arendst/Tasmota/issues/13427) ### Fixed +- Initial reset RTC memory based variables like EnergyToday and EnergyTotal diff --git a/tasmota/settings.ino b/tasmota/settings.ino index a9df2fd4d..e64e0cec1 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -38,28 +38,8 @@ uint32_t GetRtcSettingsCrc(void) { void RtcSettingsSave(void) { RtcSettings.baudrate = Settings->baudrate * 300; if (GetRtcSettingsCrc() != rtc_settings_crc) { - RtcSettings.valid = RTC_MEM_VALID; -#ifdef ESP8266 - ESP.rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); -#endif // ESP8266 -#ifdef ESP32 - RtcDataSettings = RtcSettings; -#endif // ESP32 - rtc_settings_crc = GetRtcSettingsCrc(); - } -} -bool RtcSettingsLoad(uint32_t update) { -#ifdef ESP8266 - ESP.rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); // 0x290 -#endif // ESP8266 -#ifdef ESP32 - RtcSettings = RtcDataSettings; -#endif // ESP32 - - bool read_valid = (RTC_MEM_VALID == RtcSettings.valid); - if (update) { - if (!read_valid) { + if (RTC_MEM_VALID != RtcSettings.valid) { memset(&RtcSettings, 0, sizeof(RtcSettings)); RtcSettings.valid = RTC_MEM_VALID; RtcSettings.energy_kWhtoday = Settings->energy_kWhtoday; @@ -75,9 +55,32 @@ bool RtcSettingsLoad(uint32_t update) { RtcSettings.power = Settings->power; // RtcSettings.baudrate = Settings->baudrate * 300; RtcSettings.baudrate = APP_BAUDRATE; + } + +#ifdef ESP8266 + ESP.rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); +#endif // ESP8266 +#ifdef ESP32 + RtcDataSettings = RtcSettings; +#endif // ESP32 + + rtc_settings_crc = GetRtcSettingsCrc(); + } +} + +bool RtcSettingsLoad(uint32_t update) { +#ifdef ESP8266 + ESP.rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); // 0x290 +#endif // ESP8266 +#ifdef ESP32 + RtcSettings = RtcDataSettings; +#endif // ESP32 + + bool read_valid = (RTC_MEM_VALID == RtcSettings.valid); + if (update) { + if (!read_valid) { RtcSettingsSave(); } - rtc_settings_crc = GetRtcSettingsCrc(); } return read_valid; }