timesync fixes
This commit is contained in:
parent
6a6e584234
commit
6d26dd8e08
@ -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()) &&
|
||||||
|
(gps.date.isValid())) {
|
||||||
|
|
||||||
if ((gps.time.age() < gpsDelay_ms) && (gps.time.isValid()) &&
|
ESP_LOGD(TAG, "GPS time age: %dms, is valid: %s, second: %d",
|
||||||
(gps.date.isValid())) {
|
gps.time.age(),
|
||||||
|
(gps.time.isValid() && gps.date.isValid()) ? "yes" : "no",
|
||||||
|
gps.time.second());
|
||||||
|
|
||||||
ESP_LOGD(TAG, "GPS time age: %dms, is valid: %s, second: %d, trials: %d",
|
t = tmConvert(gps.date.year(), gps.date.month(), gps.date.day(),
|
||||||
gps.time.age(),
|
gps.time.hour(), gps.time.minute(), gps.time.second());
|
||||||
(gps.time.isValid() && gps.date.isValid()) ? "yes" : "no",
|
|
||||||
gps.time.second(), i);
|
|
||||||
|
|
||||||
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);
|
return timeIsValid(t);
|
||||||
} // get_gpstime()
|
} // get_gpstime()
|
||||||
|
@ -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");
|
||||||
|
@ -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;
|
||||||
|
|
||||||
@ -78,7 +82,7 @@ uint8_t timepulse_init() {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
// use ESP32 hardware timer as time base with adjustable frequency
|
// use ESP32 hardware timer as time base with adjustable frequency
|
||||||
ppsIRQ = timerBegin(1, 8000, true); // set 80 MHz prescaler to 1/10000 sec
|
ppsIRQ = timerBegin(1, 8000, true); // set 80 MHz prescaler to 1/10000 sec
|
||||||
timerAlarmWrite(ppsIRQ, 10000, true); // 1000ms
|
timerAlarmWrite(ppsIRQ, 10000, true); // 1000ms
|
||||||
ESP_LOGI(TAG, "Timepulse: internal (ESP32 hardware timer)");
|
ESP_LOGI(TAG, "Timepulse: internal (ESP32 hardware timer)");
|
||||||
return 1; // success
|
return 1; // success
|
||||||
|
Loading…
Reference in New Issue
Block a user