Dont write guesstimates into RTC
This commit is contained in:
@@ -345,8 +345,8 @@ static double computeCorrectedElapsedSec(uint64_t lpNow, float tempNow) {
|
|||||||
/// Capture current time + LP timer into RTC memory, and epoch into NVS.
|
/// Capture current time + LP timer into RTC memory, and epoch into NVS.
|
||||||
static void capture(bool lpValid) {
|
static void capture(bool lpValid) {
|
||||||
rtcEpoch = time(nullptr);
|
rtcEpoch = time(nullptr);
|
||||||
// Update DS3231
|
// Update DS3231 only when the current time is authoritative.
|
||||||
if (initExternalRTC()) {
|
if (initExternalRTC() && !clockApproximate) {
|
||||||
writeExternalRTC(rtcEpoch);
|
writeExternalRTC(rtcEpoch);
|
||||||
}
|
}
|
||||||
rtcLpTimeUs = esp_clk_rtc_time();
|
rtcLpTimeUs = esp_clk_rtc_time();
|
||||||
@@ -393,6 +393,8 @@ bool syncNtp() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NTP sync yields authoritative time; allow DS3231 to be updated.
|
||||||
|
clockApproximate = false;
|
||||||
capture(false);
|
capture(false);
|
||||||
nvsWriteSyncTime(rtcEpoch);
|
nvsWriteSyncTime(rtcEpoch);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user