From f68fbc39e4403b57b28b1fba1f69b34fd7019ec3 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Fri, 17 Apr 2026 23:19:42 +0200 Subject: [PATCH] Dont write guesstimates into RTC --- lib/hal/HalClock.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/hal/HalClock.cpp b/lib/hal/HalClock.cpp index 1055bd30..81cf472a 100644 --- a/lib/hal/HalClock.cpp +++ b/lib/hal/HalClock.cpp @@ -345,8 +345,8 @@ static double computeCorrectedElapsedSec(uint64_t lpNow, float tempNow) { /// Capture current time + LP timer into RTC memory, and epoch into NVS. static void capture(bool lpValid) { rtcEpoch = time(nullptr); - // Update DS3231 - if (initExternalRTC()) { + // Update DS3231 only when the current time is authoritative. + if (initExternalRTC() && !clockApproximate) { writeExternalRTC(rtcEpoch); } rtcLpTimeUs = esp_clk_rtc_time(); @@ -393,6 +393,8 @@ bool syncNtp() { return false; } + // NTP sync yields authoritative time; allow DS3231 to be updated. + clockApproximate = false; capture(false); nvsWriteSyncTime(rtcEpoch);