From 74239d77f4e57c720de25c27c815386a50b1ca94 Mon Sep 17 00:00:00 2001 From: Oliver Seiler Date: Sun, 27 Sep 2020 17:35:27 +1300 Subject: [PATCH] Fix: issue #639, if no LORA time source available and GPS time in first call is invalid, then time will never get updated from GPS https://github.com/cyberman54/ESP32-Paxcounter/issues/639 --- src/timekeeper.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index 6d8439ec..1c65d9a1 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -35,8 +35,10 @@ void calibrateTime(void) { timesync_request(); #endif - // (only!) if we lost time, we try to fallback to local time source RTS or GPS - if (timeSource == _unsynced) { + // if no LORA timesource is available, or if we lost time, then fallback to + // local time source RTS or GPS + if (((!TIME_SYNC_LORASERVER) && (!TIME_SYNC_LORAWAN)) || + (timeSource == _unsynced)) { // has RTC -> fallback to RTC time #ifdef HAS_RTC @@ -47,7 +49,10 @@ void calibrateTime(void) { // no RTC -> fallback to GPS time #if (HAS_GPS) t = get_gpstime(&t_msec); - timeSource = _gps; + if (t) { + // only set time source to GPS if GPS time was actually valid + timeSource = _gps; + } #endif if (t)