Getting Hour and Minutes from ESP32 RTC
Posted: Sun Dec 08, 2024 6:13 pm
Hello,
I'm working with Espressif-IDE and framework 5.3.1. I am able to get the updated time from SNTP and have it written to the ESP32 RTC. And I can also retrieve individual elements of the RTC time using specifiers in the strftime function, for example
strftime(MY_TIME, sizeof(MY_TIME), "%I:%M%p", &timeinfo);
or
strftime(MY_HOUR, sizeof(MY_HOUR), "%I", &timeinfo);
The problem I have is ultimately I am using an external RTC chip for my timekeeping, MCP79510 over SPI. This too is working fine. I can read the individual registers, create a string and write it to my oled display.
The external SPI RTC needs to have the data written to each register as uint8_t values. But the values retrieved from the internal RTC are string values. How can I get for example the HOUR value as a uint8_t to be able to write it to the external RTC?
Order of operation:
Get SNTP time > write to internal RTC > read internal RTC individual elements (HOUR, MINUTE) > write uint8_t HOUR,MINUTE to external RTC.
In Arduino, I can see there are functions such as getMinute(), getHour() but I see nothing in ESP-IDF that does the same.
Any help is appreciated, going nuts trying to figure it out.
I'm working with Espressif-IDE and framework 5.3.1. I am able to get the updated time from SNTP and have it written to the ESP32 RTC. And I can also retrieve individual elements of the RTC time using specifiers in the strftime function, for example
strftime(MY_TIME, sizeof(MY_TIME), "%I:%M%p", &timeinfo);
or
strftime(MY_HOUR, sizeof(MY_HOUR), "%I", &timeinfo);
The problem I have is ultimately I am using an external RTC chip for my timekeeping, MCP79510 over SPI. This too is working fine. I can read the individual registers, create a string and write it to my oled display.
The external SPI RTC needs to have the data written to each register as uint8_t values. But the values retrieved from the internal RTC are string values. How can I get for example the HOUR value as a uint8_t to be able to write it to the external RTC?
Order of operation:
Get SNTP time > write to internal RTC > read internal RTC individual elements (HOUR, MINUTE) > write uint8_t HOUR,MINUTE to external RTC.
In Arduino, I can see there are functions such as getMinute(), getHour() but I see nothing in ESP-IDF that does the same.
Any help is appreciated, going nuts trying to figure it out.