19 const char * Timer::ntp_server_ =
"pool.ntp.org";
23 Serial.println(
"\n----Time Synced-----");
31 if (!getLocalTime(&timeinfo)) {
32 Serial.println(
"Failed to obtain time");
47 auto tim = mktime(&timeinfo);
48 Serial.printf(
"Epoch time: %ld\n", tim);
49 Serial.println(&timeinfo,
"%A, %B %d %Y %H:%M:%S");
54 while (WiFi.status() != WL_CONNECTED) {
56 Serial.println(
"WiFi not connected ...");
60 sntp_set_sync_interval(sync_interval_ms);
61 configTzTime(
"Etc/GMT", ntp_server_);
void begin(long int sync_interval_ms=600000)
initialise the timer, set a sync interval to sync with NTP server
void print_utc_time()
Print the seconds since epoch.
tm get_utc_time()
Get the utc time now.
time_t get_epoch_time()
Get the seconds since epoch now.
void timeSyncCallback(struct timeval *tv)