what is the preferred way to realize a datetime clock on ESP32?
I'd like to get a reference time from the internet (e.g. via NTP) and set a local clock.
The only thing I have found is xTaskGetTickCount().
Using this I can imagine something like
Code: Select all
uint32_t offset;
void init_timestamp() {
// get current timestamp from the internet
uint32_t ntp_timestamp = ntp_get_timestamp();
offset = ntp_timestamp - xTaskGetTickCount() / (portTICK_RATE_MS * 1000);
}
uint32_t get_timestamp() {
return offset + xTaskGetTickCount() / (portTICK_RATE_MS * 1000);
}
Is there a better solution?
Thank you!
Best,
Malte