What library should be used to get time and date on regular intervals for controlling purposes?
Paul Stoffregen developed the TimeLib.h library which seems to call for NTPpackets over UDP which need to be parsed while NTPClient.h simply calls for an update of timeClient.update()
NTPClient.h unless I am mistaken can only get time and day of the week.
While TimeLib.h gets complete time and date (dd/mm/yyyy)?
int getDay() const;
int getHours() const;
int getMinutes() const;
int getSeconds() const;
...
/**
* @return time formatted like `hh:mm:ss`
*/
String getFormattedTime() const;
/**
* @return time in seconds since Jan. 1, 1970
*/
unsigned long getEpochTime() const;
with getEpochTime() you can use all the usual time functions from time.h (or TimeLib.h).
that depends on the micrcontroller you are using.
For example for the ESP32 or ESP8266 you should use the time.h which comes with the platform package (core).
no.
ESP32 and ESP8266 have their own time.h (small t) implementation. You don't need a 3rd party library for NTP on these microcontrollers as it is already part of the platform package (part of the ESP core).
With Serial.println(timeClient.getEpochTime()); I get the number of seconds from 1970. But how do I convert this to day, month and year in a byte each?
the ESPs have (some kind of) RTC.
The NTP polling interval is handled in the background.
When you just try to get current time, you get the time from the RTC.
Meaning, a time(&now); // read the current time does not cause a NTP call - it reads the current time from its internal RTC.
The interval of the NTP calls is fixed, but you can change it. The example sketch (from the ZIP) also includes how to change it, but frankly, I seldom change the default.
Furthermore, there is an example how to define a callback when the NTP call is initated.