Commit Graph
2 Commits
Author SHA1 Message Date
bonamin e89a1b623f fix(TimeKeeper): guard NTP sync against reconnect storms and bad readings
Field units on unstable internet had RTC time drift wildly (10 min to
half a day), while units with stable internet stayed accurate. Root
cause: syncTimeWithNTP() wrote getLocalTime()'s result straight to the
RTC with no plausibility check, and fires on every WiFi reconnect
(not a fixed schedule) — so flaky links produced far more unguarded
sync attempts than healthy ones. The underlying configTime()/
getLocalTime() API has no request/response correlation, so a stale
reply from an abandoned attempt could be picked up by a later
attempt's window if reconnects outpaced a single attempt's ~5s resolve
time.

Three layers of defense, all in TimeKeeper:
- In-flight de-dup guard (ntpSyncInProgress) so only one sync attempt
  is ever listening at a time, closing the window a stale reply could
  land in.
- 10s cooldown between attempts to throttle reconnect storms.
- commitNtpResult(): corrections under 2 minutes commit immediately
  (normal drift); anything larger is held as a pending candidate and
  only written to the RTC once 3 consecutive syncs agree within 5s of
  each other, so a single bad reading can no longer move the clock by
  hours.

Documented in TimeKeeper/README.md under "NTP sync safety".
2026-07-20 09:08:05 +03:00
bonaminandClaude Sonnet 4.6 d4d8b1c380 docs: add per-subsystem README files
Add inline documentation for all src/ subsystems covering purpose,
responsibilities, public API, and usage notes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-14 22:16:03 +02:00