esp_netif_sntp_sync_wait returns early
Posted: Tue Sep 02, 2025 3:36 pm
Hello,
I have been trying to get SNTP to work, however when i call esp_netif_sntp_sync_wait, it returns before the time is actually set (time() returns 0).
Using the log output i can see that the time synchronizes successfully, after the function returns:
And even then current time is reported as 0
My main task:
My SNTP wrapper:
I have been trying to get SNTP to work, however when i call esp_netif_sntp_sync_wait, it returns before the time is actually set (time() returns 0).
Using the log output i can see that the time synchronizes successfully, after the function returns:
Code: Select all
I (9830) wifi_init: Got IP: 192.168.178.67
I (9830) app: sntp_begin
sntp_init: SNTP initialised
sntp_request: Waiting for server address to be resolved.
I (9840) app: sntp_wait
I (9870) wifi:<ba-add>idx:1 (ifx:0, 3c:a6:2f:8d:6f:46), tid:0, ssn:0, winSize:64
sntp_dns_found: Server address resolved, sending request
sntp_send_request: Sending request to server
I (9890) app: Done
W (9900) app: Current time: 0
sntp_process: Tue Sep 2 15:26:12 2025
, 991467 us
sntp_recv: Scheduled next time request: 3600000 ms
W (19900) app: Current time: 0
My main task:
Code: Select all
xEventGroupWaitBits(wifi_event_group, WIFI_HAS_IP_BIT, pdFALSE, pdFALSE, portMAX_DELAY);
ESP_LOGI(TAG, "sntp_begin");
ESP_ERROR_CHECK( sntp_begin() );
ESP_LOGI(TAG, "sntp_wait");
ESP_ERROR_CHECK( sntp_wait(pdMS_TO_TICKS(10000)) );
ESP_LOGI(TAG, "Done");
ESP_LOGW(TAG, "Current time: %ld", time(NULL));
vTaskDelay(pdMS_TO_TICKS(10000));
ESP_LOGW(TAG, "Current time: %ld", time(NULL));
Code: Select all
esp_err_t sntp_begin() {
esp_sntp_config_t config = ESP_NETIF_SNTP_DEFAULT_CONFIG("pool.ntp.org");
return esp_netif_sntp_init(&config);
}
esp_err_t sntp_wait(TickType_t tout) {
return esp_netif_sntp_sync_wait(tout);
}
void sntp_end() {
esp_netif_sntp_deinit();
}