Closed Schawen closed 2 years ago
The library description points out, that
After that, synchronization is done regularly without user intervention. Some parameters can be adjusted: server, sync frequency, time zone.
You don't need anything more. Time update is managed inside library so, after NTP.begin() no more calls to library are needed.
Together with the "advancedExample" code I became confused ...
`void ntpEventHandler (NTPEvent_t e) { //Serial.printf("NTP Event: %s\n", NTP.ntpEvent2str (e)); if (e.event == timeSyncd || e.event == partlySync) { time_t utcTime = time (NULL); tm* currentTime = localtime (&utcTime); // Serial.printf ("Year: %d\n", currentTime->tm_year + 1900); // Serial.printf ("Month: %d\n", currentTime->tm_mon + 1); // Serial.printf ("Day: %d\n", currentTime->tm_mday); // Serial.printf ("Hour: %d\n", currentTime->tm_hour); // Serial.printf ("Minute: %d\n", currentTime->tm_min); // Serial.printf ("Second: %d\n", currentTime->tm_sec);
setTime (currentTime->tm_hour, currentTime->tm_min, currentTime->tm_sec, currentTime->tm_mday, currentTime->tm_mon + 1, currentTime->tm_year + 1900);
}
}`
I expected to get the same results from the following "code":
Do I need to update the local time system on my own (by Interrupts)?
Is there a method to request the NTP time as time_t and not as String?