Page 1 of 1

Some basic questions about netif_sntp

Posted: Mon Dec 01, 2025 1:10 am
by nsayer
I'm making a relatively simple WiFi NTP clock.

I guess one bit of my confusion is that there appears to be both the netif SNTP implementation and the LWIP one. I would assume that you have to pick one or the other.

The behavior I desire is that the first sync be with immediate mode, and the rest of them are smooth. If I attempt to set smooth_sync true during the init(), then esp_netif_sntp_sync_wait just loops "forever." What I have done is start with the config with smooth_sync false, then after the first return of sync_wait() with ESP_OK, I just set the smooth_sync field in the config object to true, but I have no idea if that will actually affect the SNTP service. Will it? Is there some other way to change the mode? I see a lot more API entry points in the LWIP SNTP implementation... should I be using that instead?

The second question is, I really want to be able to check the quality of the current synchronization. Like, I want to put up some kind of error message if the sync hasn't happened in some sufficiently long amount of time, or if the last time sync was "way off" or some such. It looks like the only mechanism available is to register a sync callback and just keep track of how long it's been since that callback was called. How often should it be called, and what can I expect the maximum drift over that time for an ESP32-C3-mini-1-N4X to be?

The goal here is that with a local stratum 1 SNTP server the clock can stay within a couple dozen ms. That doesn't sound to me like it ought to be unrealistic.

Re: Some basic questions about netif_sntp

Posted: Mon Dec 01, 2025 7:34 am
by nopnop2002
Here is official example.
https://github.com/espressif/esp-idf/tr ... ocols/sntp

You can select Time synchronization method with menuconfig.

The SNTP client task runs on background.
The time is synchronized every 3600000 milliseconds (1 hour).
This interval can be changed using sntp_set_sync_interval().