Time - RTC vs ESP32 Clocks
-
Want to better understand if there is a difference between controllers with an RTC and 'software' time of an ESP32. Perhaps I am overthinking this...
I have a DinMeter based on a StampS3 that also includes a BM8563 RTC chip. Looking through example code for NTP sync time, I see the following:
auto dt = DinMeter.Rtc.getDateTime(); Serial.printf("RTC UTC :%04d/%02d/%02d (%s) %02d:%02d:%02d\r\n", dt.date.year, dt.date.month, dt.date.date, wd[dt.date.weekDay], dt.time.hours, dt.time.minutes, dt.time.seconds); DinMeter.Display.setCursor(0, 0); DinMeter.Display.printf("RTC UTC :%04d/%02d/%02d (%s) %02d:%02d:%02d", dt.date.year, dt.date.month, dt.date.date, wd[dt.date.weekDay], dt.time.hours, dt.time.minutes, dt.time.seconds); /// ESP32 internal timer/// auto t = time(nullptr); { auto tm = gmtime(&t); // for UTC. Serial.printf("ESP32 UTC :%04d/%02d/%02d (%s) %02d:%02d:%02d\r\n", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, wd[tm->tm_wday], tm->tm_hour, tm->tm_min, tm->tm_sec); DinMeter.Display.setCursor(0, 20); DinMeter.Display.printf("ESP32 UTC :%04d/%02d/%02d (%s) %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, wd[tm->tm_wday], tm->tm_hour, tm->tm_min, tm->tm_sec); }
It looks to me like the first section is getting the time data from the RTC. The comment 'ESP32 Internal Timer' makes me think that perhaps the 2nd section is getting time data from a software clock routine. Is that a correct understanding? Could the software time drift from the RTC time?
I'm not sure how the M5Stack software handles this - it could be that the 'software time' is always sourced from the RTC for controllers that have that option. My project requires time accuracy, so I want to ensure that I'm using the RTC as opposed to any 'software' time driven by the cpu clock.
Thoughts?