27 SUPLA_LOG_DEBUG(
"Unable to find RTC");
29 struct tm timeinfo {};
31 RTCLostPower = (rtc.lostPower()) ? true :
false;
32 DateTime now = rtc.now();
34 timeinfo.tm_year = now.year() - 1900;
35 timeinfo.tm_mon = now.month() - 1;
36 timeinfo.tm_mday = now.day();
37 timeinfo.tm_hour = now.hour();
38 timeinfo.tm_min = now.minute();
39 timeinfo.tm_sec = now.second();
41 localtime = mktime(&timeinfo);
43#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
44 timeval tv = {localtime, 0};
45 settimeofday(&tv,
nullptr);
46#elif defined(ARDUINO_ARCH_AVR)
47 set_system_time(mktime(&timeinfo));
49 printCurrentTime(
"from RTC:");
51 if (getYear() >= 2023) {
54 SUPLA_LOG_DEBUG(
"Clock is not ready");
59 bool rtcIsReady()
const {
63 bool getRTCLostPowerFlag()
const {
67 void resetRTCLostPowerFlag() {
72 struct tm timeinfo {};
74 printCurrentTime(
"current");
76 timeinfo.tm_year = result->year - 1900;
77 timeinfo.tm_mon = result->month - 1;
78 timeinfo.tm_mday = result->day;
79 timeinfo.tm_hour = result->hour;
80 timeinfo.tm_min = result->min;
81 timeinfo.tm_sec = result->sec;
83 localtime = mktime(&timeinfo);
85#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
86 timeval tv = {localtime, 0};
87 settimeofday(&tv,
nullptr);
88#elif defined(ARDUINO_ARCH_AVR)
89 set_system_time(mktime(&timeinfo));
92 printCurrentTime(
"new");
96 DateTime now = rtc.now();
97 if ((now.year() != getYear()) || (now.month() != getMonth()) ||
98 (now.day() != getDay()) || (now.hour() != getHour()) ||
99 (now.minute() != getMin()) || (now.second() - getSec() > 5) ||
100 (now.second() - getSec() < -5)) {
101 rtc.adjust(DateTime(getTimeStamp()));
102 SUPLA_LOG_DEBUG(
"Update RTC time from server");
109 bool RTCLostPower =
false;
110 bool isRTCReady =
false;