timesync fixes

This commit is contained in:
Verkehrsrot 2019-03-03 17:35:08 +01:00
parent 6a6e584234
commit 6d26dd8e08
3 changed files with 16 additions and 17 deletions

View File

@ -81,21 +81,16 @@ time_t get_gpstime(void) {
time_t t = 0; time_t t = 0;
for (uint8_t i = 0; i <= 9; i++) { // trying to get a recent time.age
if ((gps.time.age() < gpsDelay_ms) && (gps.time.isValid()) && if ((gps.time.age() < gpsDelay_ms) && (gps.time.isValid()) &&
(gps.date.isValid())) { (gps.date.isValid())) {
ESP_LOGD(TAG, "GPS time age: %dms, is valid: %s, second: %d, trials: %d", ESP_LOGD(TAG, "GPS time age: %dms, is valid: %s, second: %d",
gps.time.age(), gps.time.age(),
(gps.time.isValid() && gps.date.isValid()) ? "yes" : "no", (gps.time.isValid() && gps.date.isValid()) ? "yes" : "no",
gps.time.second(), i); gps.time.second());
t = tmConvert(gps.date.year(), gps.date.month(), gps.date.day(), t = tmConvert(gps.date.year(), gps.date.month(), gps.date.day(),
gps.time.hour(), gps.time.minute(), gps.time.second()); gps.time.hour(), gps.time.minute(), gps.time.second());
break; // exit for
}
} }
return timeIsValid(t); return timeIsValid(t);
} // get_gpstime() } // get_gpstime()

View File

@ -465,9 +465,9 @@ void user_request_network_time_callback(void *pVoidUserUTCTime,
// Update system time with time read from the network // Update system time with time read from the network
if (timeIsValid(*pUserUTCTime)) { if (timeIsValid(*pUserUTCTime)) {
xSemaphoreTake(TimePulse, pdMS_TO_TICKS(1000)); // wait for pps setTime(*pUserUTCTime);
setTime(*pUserUTCTime + 1);
timeSource = _lora; timeSource = _lora;
timesyncer.attach(TIME_SYNC_INTERVAL * 60, timeSync); // regular repeat
ESP_LOGI(TAG, "Received recent time from LoRa"); ESP_LOGI(TAG, "Received recent time from LoRa");
} else } else
ESP_LOGI(TAG, "Invalid time received from LoRa"); ESP_LOGI(TAG, "Invalid time received from LoRa");

View File

@ -21,6 +21,7 @@ time_t timeProvider(void) {
set_rtctime(t); // calibrate RTC set_rtctime(t); // calibrate RTC
#endif #endif
timeSource = _gps; timeSource = _gps;
timesyncer.attach(TIME_SYNC_INTERVAL * 60, timeSync); // regular repeat
return t; return t;
} }
#endif #endif
@ -30,6 +31,7 @@ time_t timeProvider(void) {
t = get_rtctime(); t = get_rtctime();
if (t) { if (t) {
timeSource = _rtc; timeSource = _rtc;
timesyncer.attach(60, timeSync); // short retry
} }
#endif #endif
@ -38,8 +40,10 @@ time_t timeProvider(void) {
LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime); LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime);
#endif #endif
if (!t) if (!t) {
timeSource = _unsynced; timeSource = _unsynced;
timesyncer.attach(60, timeSync); // short retry
}
return t; return t;