From 2f63895599ee28283cb0a7bd397165c4f6f2ac7b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 5 Jan 2021 10:37:05 +0100 Subject: [PATCH] Fix RTOS time update (#10334) --- tasmota/support_rtc.ino | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tasmota/support_rtc.ino b/tasmota/support_rtc.ino index 9884b337f..e9afa4597 100644 --- a/tasmota/support_rtc.ino +++ b/tasmota/support_rtc.ino @@ -400,15 +400,6 @@ void RtcSecond(void) } else { TasmotaGlobal.rules_flag.time_set = 1; } - -#ifdef ESP32 - // Sync RTOS time to be used by SD Card time stamps - struct timeval tv; - tv.tv_sec = Rtc.local_time; - tv.tv_usec = 0; - settimeofday(&tv, nullptr); -#endif // ESP32 - } else { Rtc.utc_time++; // Increment every second } @@ -463,6 +454,17 @@ void RtcSecond(void) Rtc.midnight = Rtc.local_time; Rtc.midnight_now = true; } + +#ifdef ESP32 + if (mutex) { // Time is just synced and is valid + // Sync RTOS time to be used by SD Card time stamps + struct timeval tv; + tv.tv_sec = Rtc.local_time; + tv.tv_usec = 0; + settimeofday(&tv, nullptr); + } +#endif // ESP32 + } RtcTime.year += 1970;