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;
for (uint8_t i = 0; i <= 9; i++) { // trying to get a recent time.age
if ((gps.time.age() < gpsDelay_ms) && (gps.time.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.isValid() && gps.date.isValid()) ? "yes" : "no",
gps.time.second(), i);
gps.time.second());
t = tmConvert(gps.date.year(), gps.date.month(), gps.date.day(),
gps.time.hour(), gps.time.minute(), gps.time.second());
break; // exit for
}
}
return timeIsValid(t);
} // 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
if (timeIsValid(*pUserUTCTime)) {
xSemaphoreTake(TimePulse, pdMS_TO_TICKS(1000)); // wait for pps
setTime(*pUserUTCTime + 1);
setTime(*pUserUTCTime);
timeSource = _lora;
timesyncer.attach(TIME_SYNC_INTERVAL * 60, timeSync); // regular repeat
ESP_LOGI(TAG, "Received recent time from LoRa");
} else
ESP_LOGI(TAG, "Invalid time received from LoRa");

View File

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