I'm trying to use the SNTP sync facility as described in the docs, and demonstrated in the example. The results are all over the map - sometimes it syncs really quickly; sometimes it takes a while, and sometimes it never does. I'm wondering what I'm doing to cause this.
v4.1 of the IDF; running on WROVER.
Here's my initialization code (called once):
Code: Select all
setTimeZone(m_tasks->flash->get(NVS_KEY_TIMEZONE));
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, m_tasks->flash->get(NVS_KEY_NTP_SERVER).c_str());
sntp_init();
Code: Select all
esp_err_t Wifi::sntpSync()
{
const int MAX_TRIES = 10;
esp_err_t err;
int retry = 0;
time_t now = 0;
while (sntp_get_sync_status() == SNTP_SYNC_STATUS_RESET && ++retry < MAX_TRIES)
{
ESP_LOGI(TAG, "sntpSync(): attempting to sync SNTP (%d/%d).", retry, MAX_TRIES);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
if (retry < MAX_TRIES)
{
ESP_LOGI(TAG, "sntpSync(): time is synced.");
time(&now);
err = ESP_OK;
}
else
{
ESP_LOGE(TAG, "sntpSync(): failed to sync time.");
err = ESP_FAIL;
sntp_restart();
}
return err;
}
Thanks...