Skip to content

Commit becd3fa

Browse files
Wessel Nieboerweebl2000
authored andcommitted
Sync time with GPS every 30 minutes
Unless your GPS is being spoofed there isn't really a downside to syncing more often with GPS. I understand the RTC is very stable, but especially with powersaving now clock drift is worse, we should sync more often.
1 parent e6e87fb commit becd3fa

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/helpers/sensors/MicroNMEALocationProvider.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class MicroNMEALocationProvider : public LocationProvider {
4343
int _pin_en;
4444
long next_check = 0;
4545
long time_valid = 0;
46+
unsigned long _last_time_sync = 0;
47+
static const unsigned long TIME_SYNC_INTERVAL = 1800000; // Re-sync every 30 minutes
4648

4749
public :
4850
MicroNMEALocationProvider(Stream& ser, mesh::RTCClock* clock = NULL, int pin_reset = GPS_RESET, int pin_en = GPS_EN,RefCountedDigitalPin* peripher_power=NULL) :
@@ -126,10 +128,15 @@ public :
126128

127129
if (millis() > next_check) {
128130
next_check = millis() + 1000;
131+
// Re-enable time sync periodically when GPS has valid fix
132+
if (!_time_sync_needed && _clock != NULL && (millis() - _last_time_sync) > TIME_SYNC_INTERVAL) {
133+
_time_sync_needed = true;
134+
}
129135
if (_time_sync_needed && time_valid > 2) {
130136
if (_clock != NULL) {
131137
_clock->setCurrentTime(getTimestamp());
132138
_time_sync_needed = false;
139+
_last_time_sync = millis();
133140
}
134141
}
135142
if (isValid()) {

0 commit comments

Comments
 (0)