From 74239d77f4e57c720de25c27c815386a50b1ca94 Mon Sep 17 00:00:00 2001 From: Oliver Seiler Date: Sun, 27 Sep 2020 17:35:27 +1300 Subject: [PATCH 1/3] 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) From 53570d7ccfad2b73ae5a0b1be147729e1d95cc13 Mon Sep 17 00:00:00 2001 From: Oliver Seiler Date: Sun, 27 Sep 2020 18:19:02 +1300 Subject: [PATCH 2/3] Add sub band channel selection for AU915 Also see https://github.com/mcci-catena/arduino-lmic/commits/master/examples/ttn-abp/ttn-abp.ino --- src/loraconf_abp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/loraconf_abp.cpp b/src/loraconf_abp.cpp index 76de2f73..675b90fa 100644 --- a/src/loraconf_abp.cpp +++ b/src/loraconf_abp.cpp @@ -39,8 +39,8 @@ void setABPParameters() { // devices' ping slots. LMIC does not have an easy way to define set this // frequency and support for class B is spotty and untested, so this // frequency is not configured here. - #elif defined(CFG_us915) - // NA-US channels 0-71 are configured automatically + #elif defined(CFG_us915) || defined(CFG_au915) + // NA-US and AU channels 0-71 are configured automatically // but only one group of 8 should (a subband) should be active // TTN recommends the second sub band, 1 in a zero based count. // https://github.com/TheThingsNetwork/gateway-conf/blob/master/US-global_conf.json From 19710bae4b9a6b964bb77703fc4f7070a5e2e29f Mon Sep 17 00:00:00 2001 From: Oliver Seiler Date: Sun, 27 Sep 2020 20:39:02 +1300 Subject: [PATCH 3/3] Fixing issue #639 in a better way, that ensures TIME_SYNC_INTERVAL_RETRY is used over TIME_SYNC_INTERVAL when GPS time was invalid --- src/timekeeper.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index 1c65d9a1..bc9e52b5 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -49,14 +49,10 @@ void calibrateTime(void) { // no RTC -> fallback to GPS time #if (HAS_GPS) t = get_gpstime(&t_msec); - if (t) { - // only set time source to GPS if GPS time was actually valid - timeSource = _gps; - } + timeSource = _gps; #endif - if (t) - setMyTime((uint32_t)t, t_msec, timeSource); // set time + setMyTime((uint32_t)t, t_msec, timeSource); // set time } // fallback