set RTC by GPS & LORA

This commit is contained in:
Klaus K Wilting 2019-01-29 09:04:56 +01:00
parent 8459eec8ef
commit 2fd3b6725c
2 changed files with 6 additions and 5 deletions

View File

@ -73,6 +73,10 @@ time_t get_gpstime(void) {
if (gps.time.age() < 1500) { if (gps.time.age() < 1500) {
t = tmConvert_t(gps.date.year(), gps.date.month(), gps.date.day(), t = tmConvert_t(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());
#ifdef HAS_RTC
if (!set_rtctime(t))
ESP_LOGE(TAG, "RTC set time failure");
#endif
} else { } else {
ESP_LOGW(TAG, "GPS has no confident time"); ESP_LOGW(TAG, "GPS has no confident time");
} }

View File

@ -455,12 +455,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
setTime(*pUserUTCTime); setTime(*pUserUTCTime);
ESP_LOGI(TAG, "LoRaWAN network has set the system time");
#ifdef HAS_RTC #ifdef HAS_RTC
if (!set_rtctime(*pUserUTCTime)) if (!set_rtctime(*pUserUTCTime))
ESP_LOGE(TAG, "RTC set time failure"); ESP_LOGE(TAG, "RTC set time failure");
#endif #endif
time_t t = myTZ.toLocal(now());
ESP_LOGI(TAG,
"LORA Network has set system time to %02d/%02d/%d %02d:%02d:%02d",
month(t), day(t), year(t), hour(t), minute(t), second(t));
} }