I wrote the following code (snippet):
Code: Select all
/* Initialize and start SNTP client */
if (cfg->client.sntp.server_no >= 1)
{
esp_sntp_setoperatingmode(ESP_SNTP_OPMODE_POLL);
esp_sntp_config_t sntp_config = ESP_NETIF_SNTP_DEFAULT_CONFIG(cfg->client.sntp.server[0]);
sntp_config.sync_cb = time_sync_event_handler;
sntp_config.start = false;
esp_netif_sntp_init(&sntp_config);
sntp_set_sync_interval(cfg->client.sntp.interval * 1000);
sntp_set_sync_status(SNTP_SYNC_STATUS_RESET);
for (i = 1; i < cfg->client.sntp.server_no; i++)
esp_sntp_setservername(i, cfg->client.sntp.server[i]);
esp_netif_sntp_start();
}
for (i = 0; i < cfg->client.sntp.server_no; i++)
{
char const *name;
name = esp_sntp_getservername(i);
ESP_LOGI(MODULE_TAG, "NTP server no. %d : %s", i, (name == NULL) ? "<NULL>" : name);
}
My server array contains two entries: "pool.ntp.org" and "time.microsoft.com" and the field cfg->client.sntp.server_no = 2.
Executing this code outputs:
Code: Select all
I (3556) WIFI: NTP server no. 0 : pool.ntp.org
I (3566) WIFI: NTP server no. 1 : <NULL>
Is something wrong in my code? Is the order of esp_??? calls wrong?
Thanks in advance,
Michael