sensors: fix millis() rollover that stalls GPS time-sync on long-uptime nodes - #2937
Merged
ripplebiz merged 1 commit intoJul 13, 2026
Merged
Conversation
next_check and next_gps_update stored a future millis() value in a signed long and compared with a naive '>'. After the ~24.8-day millis() sign flip the deadline sits above the wrapped millis(), so the block never runs again and GPS->RTC time-sync (and the location cache refresh) stall permanently until reboot. Switch to unsigned deadlines with the wrap-safe signed- difference compare '(long)(millis() - deadline) > 0', matching the idiom in Dispatcher::millisHasNowPassed. Also: reorder the MicroNMEALocationProvider ctor init-list to declaration order (silences -Wreorder) and drop the always-true 'if (_claims > 0)' guard in claim() (claim() always runs after _claims++, so it is >= 1).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MicroNMEALocationProviderandEnvironmentSensorManagerstore a futuremillis()deadline in a signed
longand compare it with a naivemillis() > deadline:millis()isuint32_t. After the ~24.8-day sign flip the stored deadline sits abovethe wrapped
millis(), somillis() > next_checkstays false and the whole block neverruns again. Because both the periodic re-arm and the actual
_clock->setCurrentTime()live inside that block, GPS→RTC time-sync (manual and automatic) stops permanently until
reboot — matching the "ran for weeks then the clock drifted / node fell off the map"
reports in #2786 (this is distinct from, and complementary to, the missing-clock-in-
constructor cause some boards also have). The same pattern in
EnvironmentSensorManager::loop()(next_gps_update) freezes the location cache refresh.Fix
Use the wrap-safe signed-difference compare already used by
Dispatcher::millisHasNowPassed(
(long)(millis() - deadline) > 0) and make the deadlinesunsigned long:src/helpers/sensors/MicroNMEALocationProvider.h:next_checksrc/helpers/sensors/EnvironmentSensorManager.cpp:next_gps_updateValid for all intervals well under 2^31 ms (here 1 s), on every platform.
Two tiny cleanups ride along in the same file: reorder the
MicroNMEALocationProviderconstructor init-list to declaration order (silences
-Wreorder), and drop the always-trueif (_claims > 0)guard inclaim()(it always runs right after_claims++).No functional change beyond fixing the rollover; no API/ABI surface touched (all changed
symbols are private/local).