Merge pull request #648 from oseiler2/GpsDrivenTimeSynch

Gps driven time synch
This commit is contained in:
Verkehrsrot 2020-09-29 17:20:55 +02:00 committed by GitHub
commit 9ac365d9ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 11 deletions

View File

@ -159,6 +159,13 @@ void gps_loop(void *pvParameters) {
delay(2); // 2ms delay according L76 datasheet delay(2); // 2ms delay according L76 datasheet
} }
#endif #endif
// if time hasn't been synchronised yet, and we have a valid GPS time,
// update time from GPS.
if (timeSource == _unsynced && gpstime.isUpdated() && gpstime.isValid()) {
calibrateTime();
}
} // if } // if
// show NMEA data in verbose mode, useful for debugging GPS, bu tvery noisy // show NMEA data in verbose mode, useful for debugging GPS, bu tvery noisy

View File

@ -488,11 +488,6 @@ void setup() {
#warning you did not specify a time source, time will not be synched #warning you did not specify a time source, time will not be synched
#endif #endif
// initialize gps time
#if (HAS_GPS)
get_gpstime();
#endif
#if (defined HAS_IF482 || defined HAS_DCF77) #if (defined HAS_IF482 || defined HAS_DCF77)
ESP_LOGI(TAG, "Starting Clock Controller..."); ESP_LOGI(TAG, "Starting Clock Controller...");
clock_init(); clock_init();

View File

@ -26,12 +26,13 @@ Ticker timesyncer;
void timeSync() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); } void timeSync() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); }
void calibrateTime(void) { void calibrateTime(void) {
ESP_LOGD(TAG, "[%0.3f] calibrateTime, timeSource == %d", millis() / 1000.0,
timeSource);
time_t t = 0; time_t t = 0;
uint16_t t_msec = 0; uint16_t t_msec = 0;
// kick off asychronous lora timesync if we have // kick off asychronous lora timesync if we have
#if (HAS_LORA) && (TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN) #if (HAS_LORA) && ((TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN))
timesync_request(); timesync_request();
#endif #endif
@ -43,17 +44,17 @@ void calibrateTime(void) {
// has RTC -> fallback to RTC time // has RTC -> fallback to RTC time
#ifdef HAS_RTC #ifdef HAS_RTC
t = get_rtctime(); t = get_rtctime();
timeSource = _rtc; // set time from RTC
setMyTime((uint32_t)t, t_msec, _rtc);
#endif #endif
// no RTC -> fallback to GPS time // no RTC -> fallback to GPS time
#if (HAS_GPS) #if (HAS_GPS)
t = get_gpstime(&t_msec); t = get_gpstime(&t_msec);
timeSource = _gps; // set time from GPS - method will check if time is valid
setMyTime((uint32_t)t, t_msec, _gps);
#endif #endif
setMyTime((uint32_t)t, t_msec, timeSource); // set time
} // fallback } // fallback
else else