26 SUPLA_LOG_DEBUG(
"Unable to find RTC");
28 struct tm timeinfo {};
30 RTCLostPower = (rtc.isrunning()) ? false :
true;
31 DateTime now = rtc.now();
33 timeinfo.tm_year = now.year() - 1900;
34 timeinfo.tm_mon = now.month() - 1;
35 timeinfo.tm_mday = now.day();
36 timeinfo.tm_hour = now.hour();
37 timeinfo.tm_min = now.minute();
38 timeinfo.tm_sec = now.second();
40 localtime = mktime(&timeinfo);
42#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
43 timeval tv = {localtime, 0};
44 settimeofday(&tv,
nullptr);
45#elif defined(ARDUINO_ARCH_AVR)
46 set_system_time(mktime(&timeinfo));
48 printCurrentTime(
"from RTC:");
50 if (getYear() >= 2023) {
53 SUPLA_LOG_DEBUG(
"Clock is not ready");
62 bool getRTCLostPowerFlag() {
66 void resetRTCLostPowerFlag() {
71 struct tm timeinfo {};
75 printCurrentTime(
"current");
77 timeinfo.tm_year = result->year - 1900;
78 timeinfo.tm_mon = result->month - 1;
79 timeinfo.tm_mday = result->day;
80 timeinfo.tm_hour = result->hour;
81 timeinfo.tm_min = result->min;
82 timeinfo.tm_sec = result->sec;
84 localtime = mktime(&timeinfo);
86#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
87 timeval tv = {localtime, 0};
88 settimeofday(&tv,
nullptr);
89#elif defined(ARDUINO_ARCH_AVR)
90 set_system_time(mktime(&timeinfo));
92 printCurrentTime(
"new");
97 DateTime now = rtc.now();
98 if ((now.year() != getYear()) || (now.month() != getMonth()) ||
99 (now.day() != getDay()) || (now.hour() != getHour()) ||
100 (now.minute() != getMin()) || (now.second() - getSec() > 5) ||
101 (now.second() - getSec() < -5)) {
102 rtc.adjust(DateTime(getTimeStamp()));
103 SUPLA_LOG_DEBUG(
"Update RTC time from server");
110 bool RTCLostPower =
false;
111 bool isRTCReady =
false;