Page 1 of 1

RTC_ESP32_NTP date/time return format

Posted: Tue Jun 13, 2023 6:39 pm
by jandidden
To verify that I could connect my ESP32 project to the 'net and communicate with another site I thought getting the time would be a good case.
Basically I can gather the date and time but the format isn't what I expected.
The returned RTC_ESP32_NPT1::GetTimeString(1) returns 00:00:00 and repeated calls in 1 sec intervals then starts to count the seconds.
So it looks that the 1st call returns 00:00:00 and next calls return the time since the 1st call, which seems a bit weird.
The returned RTC_ESP32_NTP1::GetDateString(0) returns 01/01/226.
I could have understood 01/01/2000 or something, but really expected 13/06/2023.

What am I missing? FC attached with SSID and PW blanked out.

Jan

Re: RTC_ESP32_NTP date/time return format

Posted: Tue Jun 13, 2023 8:48 pm
by BenR
Hi Jan,

Looks like you are missing a call to the QueryTimeServer macro of the RTC component. You need to do this once connected to the WIFI and then once you've done it the ESP will maintain the time on it's own. You might want to repeat the query call when possible to keep the internal timing of the ESP from drifting too far out from reality. Say once a day or once an hour should be fine.

Re: RTC_ESP32_NTP date/time return format

Posted: Tue Jun 13, 2023 9:00 pm
by jandidden
I changed the format specification bit to see what happens.
If I change the GetTimeString format it deletes the seconds and displays HH:MM only, which is according to spec.
Changing the Get DateString format has no effect, it still displays 01/01/226.
I do not plan to wait a year to see whether it turns over.

Edit: posted this before I saw Ben's post above. Will check that.

Edit2: I got this all wrong. I thought that GetTimeString and GetDateString would get the time/date from the 'net.
But I now understand that these are the ESP32 internal RTC, and I need to do a QueryTimeServer to get the time so the internal RTC knows the actual time. Duh.

Jan

Re: RTC_ESP32_NTP date/time return format

Posted: Wed Jun 14, 2023 12:05 pm
by jandidden
All well now. Once I realised I misinterpreted stuff, it fell into place.
TimeQuery successful, DateString returned 06/14/23.
Onward!

Jan