mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Allow setting RTC clock backwards and fix elapsed-time underflow
Remove the "clock cannot go backwards" restriction from all set-time paths (CLI `time`, `clock sync`, companion radio CMD_SET_DEVICE_TIME, and simple_secure_chat). The ESP32-S3 RTC drifts 5-10% during deep sleep, making backwards correction necessary after even a few days. Add safeElapsedSecs() helper in ArduinoHelpers.h that clamps elapsed time to 0 when a stored timestamp appears to be in the future after a clock correction. Applied to: - Neighbor "heard X ago" displays in simple_repeater - UI time displays in companion_radio - TimeSeriesData calculations in simple_sensor Switch BaseChatMesh connection expiry from RTC timestamps to monotonic millis(), making it immune to RTC adjustments from GPS, NTP, or manual sync. Rename last_activity to last_activity_ms to reflect the change.
This commit is contained in:
parent
fb726e48c2
commit
5f36fde054
9 changed files with 39 additions and 46 deletions
|
|
@ -158,13 +158,8 @@ class MyMesh : public BaseChatMesh, ContactVisitor {
|
|||
}
|
||||
|
||||
void setClock(uint32_t timestamp) {
|
||||
uint32_t curr = getRTCClock()->getCurrentTime();
|
||||
if (timestamp > curr) {
|
||||
getRTCClock()->setCurrentTime(timestamp);
|
||||
Serial.println(" (OK - clock set!)");
|
||||
} else {
|
||||
Serial.println(" (ERR: clock cannot go backwards)");
|
||||
}
|
||||
getRTCClock()->setCurrentTime(timestamp);
|
||||
Serial.println(" (OK - clock set!)");
|
||||
}
|
||||
|
||||
void importCard(const char* command) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue