SNTP returns same value each time
Posted: Fri Jun 10, 2022 2:17 pm
Hi all,
I have SNTP client up and running on my ESP32C3, but it returns the same value each time time is synced.
Function time_sync_cb prints:
When I try reading current timestamp with time() function later on, it returns value 62500.
The code should be pretty straightforward, after few hours of changing pools, intervals, timezones and adding more code to it, I don't see the error in the code. May it be in hardware? There are no error messages in idf monitor. And the device is connected to the WiFi.
I have SNTP client up and running on my ESP32C3, but it returns the same value each time time is synced.
Code: Select all
// Callback for time-sync event
void time_sync_cb(struct timeval *tv) {
printf("Time sync finished: %lld\n", tv->tv_sec);
}
void sntp_start() {
printf("SNTP starting\n");
// Setup TimeZone. Different values - UTC+1, EST5EDT,M3.2.0/2,M11.1.0 etc don't have any effect.
setenv("TZ", "UTC", 1);
tzset();
sntp_setservername(0, "pool.ntp.org");
sntp_set_sync_interval( 15*1000 ); // 15 s
sntp_set_time_sync_notification_cb(time_sync_cb);
sntp_set_sync_mode(SNTP_SYNC_MODE_IMMED);
sntp_init();
}
Code: Select all
Time sync finished: 77309542412
The code should be pretty straightforward, after few hours of changing pools, intervals, timezones and adding more code to it, I don't see the error in the code. May it be in hardware? There are no error messages in idf monitor. And the device is connected to the WiFi.