33class DS1307RTC :
public Clock {
39 SUPLA_LOG_DEBUG(
"Unable to find RTC");
41 struct tm timeinfo {};
43 RTCLostPower = (rtc.isrunning()) ? false :
true;
44 DateTime now = rtc.now();
46 timeinfo.tm_year = now.year() - 1900;
47 timeinfo.tm_mon = now.month() - 1;
48 timeinfo.tm_mday = now.day();
49 timeinfo.tm_hour = now.hour();
50 timeinfo.tm_min = now.minute();
51 timeinfo.tm_sec = now.second();
53 localtime = mktime(&timeinfo);
55#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
56 timeval tv = {localtime, 0};
57 settimeofday(&tv,
nullptr);
58#elif defined(ARDUINO_ARCH_AVR)
59 set_system_time(mktime(&timeinfo));
61 printCurrentTime(
"from RTC:");
63 if (getYear() >= 2023) {
66 SUPLA_LOG_DEBUG(
"Clock is not ready");
75 bool getRTCLostPowerFlag() {
79 void resetRTCLostPowerFlag() {
83 void parseLocaltimeFromServer(TSDC_UserLocalTimeResult *result) {
84 struct tm timeinfo {};
88 printCurrentTime(
"current");
90 timeinfo.tm_year = result->year - 1900;
91 timeinfo.tm_mon = result->month - 1;
92 timeinfo.tm_mday = result->day;
93 timeinfo.tm_hour = result->hour;
94 timeinfo.tm_min = result->min;
95 timeinfo.tm_sec = result->sec;
97 localtime = mktime(&timeinfo);
99#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
100 timeval tv = {localtime, 0};
101 settimeofday(&tv,
nullptr);
102#elif defined(ARDUINO_ARCH_AVR)
103 set_system_time(mktime(&timeinfo));
105 printCurrentTime(
"new");
110 DateTime now = rtc.now();
111 if ((now.year() != getYear()) || (now.month() != getMonth()) ||
112 (now.day() != getDay()) || (now.hour() != getHour()) ||
113 (now.minute() != getMin()) || (now.second() - getSec() > 5) ||
114 (now.second() - getSec() < -5)) {
115 rtc.adjust(DateTime(getTimeStamp()));
116 SUPLA_LOG_DEBUG(
"Update RTC time from server");
123 bool RTCLostPower =
false;
124 bool isRTCReady =
false;