Description
Is your feature request related to a problem?
The esp-idf lwip sntp code adjusts the boot_time (via newlib/time.c:adjtime
) for every ntp reply it receives. This is somewhat crude, and makes the boot_time
jump up and down with the (network) latency jitter on the latest ntp reply.
To make things worse, newlib/time.c:adjtime
tends to adjust the boot_time
with the maximum 15_625 usec step when a time function (gettimeofday
) is called.
Describe the solution you'd like.
The RTC clock would be much smoother if:
- SNTP adjusts the RTC clock frequency and not actual time via
boot_time
. The hardware manual mentions that the RTC_SLOW_CLK is frequency is adjustable?
SNTP in nodemcu appears to use an adjustable clock rate on ESP/ESP32: [1] and [2]:
This module can compensate for the underlying clock not running at exactly the required rate. The adjustment is in steps of 1 part in 2^32 (i.e. around 0.25 ppb). This adjustment is done automatically if the sntp.sync() is called with the autorepeat flag set. The rate is settable using the set() function below. When the platform is booted, it defaults to 0 (i.e. nominal). A sample of modules shows that the actual clock rate is temperature dependant, but is normally within 5ppm of the nominal rate. This translates to around 15 seconds per month.
- Clock-disicpline with a PLL was used. sntp in nodemcu appears to use this as well on ESP32: [1]
Additional context.
- https://kb.meinbergglobal.com/kb/time_sync/ntp/ntp_basics
- https://github.com/troglobit/sntpd/blob/master/src/phaselock.c
I (29524) sn_time: 2023-07-14 10:23:53.166652 => delta:3288
I (44544) sn_time: 2023-07-14 10:24:08.186546 => delta:544
I (59564) sn_time: 2023-07-14 10:24:23.206837 => delta:-117
I (74584) sn_time: 2023-07-14 10:24:38.226897 => delta:306
I (89604) sn_time: 2023-07-14 10:24:53.251079 => delta:131
I (104634) sn_time: 2023-07-14 10:25:08.277078 => delta:87
I (119654) sn_time: 2023-07-14 10:25:23.297100 => delta:45
I (134674) sn_time: 2023-07-14 10:25:38.317357 => delta:204
I (149694) sn_time: 2023-07-14 10:25:53.337909 => delta:-653
I (164724) sn_time: 2023-07-14 10:26:08.367555 => delta:843
I (179744) sn_time: 2023-07-14 10:26:23.387485 => delta:43
I (194764) sn_time: 2023-07-14 10:26:38.407605 => delta:125
I (209784) sn_time: 2023-07-14 10:26:53.427703 => delta:48
I (224804) sn_time: 2023-07-14 10:27:08.447954 => delta:163
I (239824) sn_time: 2023-07-14 10:27:23.472600 => delta:-31
I (254854) sn_time: 2023-07-14 10:27:38.497943 => delta:-165
I (269874) sn_time: 2023-07-14 10:27:53.518400 => delta:-1253 <==== back
I (284904) sn_time: 2023-07-14 10:28:08.551199 => delta:1633 <===== forwards
I (299934) sn_time: 2023-07-14 10:28:23.582582 => delta:456
I (314964) sn_time: 2023-07-14 10:28:38.608522 => delta:-51
I (329984) sn_time: 2023-07-14 10:28:53.630121 => delta:32
I (345014) sn_time: 2023-07-14 10:29:08.658714 => delta:194
I (360034) sn_time: 2023-07-14 10:29:23.678893 => delta:63
I (375054) sn_time: 2023-07-14 10:29:38.700546 => delta:99
I (390084) sn_time: 2023-07-14 10:29:53.730622 => delta:-77
I (405114) sn_time: 2023-07-14 10:30:08.758977 => delta:292
I (420134) sn_time: 2023-07-14 10:30:23.779957 => delta:15
I (435164) sn_time: 2023-07-14 10:30:38.809235 => delta:148
I (450184) sn_time: 2023-07-14 10:30:53.829423 => delta:181
I (465204) sn_time: 2023-07-14 10:31:08.849585 => delta:18
I (480224) sn_time: 2023-07-14 10:31:23.869592 => delta:104
I (495244) sn_time: 2023-07-14 10:31:38.889729 => delta:-68
I (510264) sn_time: 2023-07-14 10:31:53.909615 => delta:-3357 <==== back
I (525294) sn_time: 2023-07-14 10:32:08.939931 => delta:3719 <===== forwards
I (540314) sn_time: 2023-07-14 10:32:23.959807 => delta:49
I (555334) sn_time: 2023-07-14 10:32:38.979908 => delta:144
I (570354) sn_time: 2023-07-14 10:32:54.000191 => delta:183
I (585374) sn_time: 2023-07-14 10:33:09.020238 => delta:37
I (600394) sn_time: 2023-07-14 10:33:24.042006 => delta:71
I (615424) sn_time: 2023-07-14 10:33:39.071071 => delta:-615 <==== back
I (630454) sn_time: 2023-07-14 10:33:54.100612 => delta:809 <===== forwards
I (645474) sn_time: 2023-07-14 10:34:09.120410 => delta:94
I (660494) sn_time: 2023-07-14 10:34:24.140744 => delta:40
I (675514) sn_time: 2023-07-14 10:34:39.160683 => delta:169
I (690534) sn_time: 2023-07-14 10:34:54.181013 => delta:-1521 <==== back
I (705564) sn_time: 2023-07-14 10:35:09.214118 => delta:1641 <===== forwards
I (720594) sn_time: 2023-07-14 10:35:24.241221 => delta:56
I (735614) sn_time: 2023-07-14 10:35:39.261133 => delta:11
I (750634) sn_time: 2023-07-14 10:35:54.281261 => delta:208
Activity