SNTP accuracy

grumpyEngineer12
Posts: 5
Joined: Fri Jan 14, 2022 2:24 am

SNTP accuracy

Postby grumpyEngineer12 » Sun Jan 16, 2022 12:22 am

Hi everyone,

excuse the noob question, but I'm trying to analytically determine the largest error possible using the standard LWIP implementation of SNTP which is included.

For my use-case I will be running an NTP sever on a local machine on a local network. For me it's very important that the delta between what the ESP thinks is the current time and the local machine is _VERY_ small - I don't know how to analytically measure this.

I set up a simple experiment in which two separate ESP32s connect to the NTP server, get the time, and then toggle a GPIO every second.

Looking at the GPIO waveform on a scope, I can se that the error between the two ESPs is fairly small (few ms) - however, I don't know how to measure the error between the ESP32 and the local machine. my local machine is running Ubunto and I don't know how to get a GPIO out of it, and even if I did I don't know what the delay is in terms of toggling a GPIO

How can I determine in this case? Does not sound easy!

Thanks!

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: SNTP accuracy

Postby ESP_Sprite » Sun Jan 16, 2022 1:33 am

Nothing noob-ish about that, it's actually a somewhat hard issue... my thought is that perhaps you don't want to get an output from the PC, but you can input data to your PC. Serial ports will have some latency (specifically in the USB-to-serial converter), so you may not want the obvious solution of using the serial channel to feed back data, but how about getting an old computer mouse, opening it up, and letting the GPIO output of the ESP32 short one of the mouse buttons? All you need on the PC side is something that prints out a timestamp when a click occurs. Should give you up to a millisecond of precision.

grumpyEngineer12
Posts: 5
Joined: Fri Jan 14, 2022 2:24 am

Re: SNTP accuracy

Postby grumpyEngineer12 » Sun Jan 16, 2022 9:32 am

Thank you, mouse is a pretty good idea, creative thinking for sure :)

Another idea I had (in-case anyone ever is in the same spot as me) is to put the NTP server on a raspberry pi since then then it's possible to have close to single CPU cycle (well, close enough) of GPIOs.

I have enough to go and give it a try, will report back what I find in-case anyone else is curious in the future!

Craige Hales
Posts: 94
Joined: Tue Sep 07, 2021 12:07 pm

Re: SNTP accuracy

Postby Craige Hales » Sun Jan 16, 2022 11:57 am

I think the esp's default SNTP sync interval is an hour. The clocks could easily drift apart 100ms in an hour.

https://en.wikipedia.org/wiki/Network_T ... ol#History was a fun read.
Craige

Who is online

Users browsing this forum: Google [Bot] and 111 guests