Clock skew

davepl
Posts: 29
Joined: Wed Jun 27, 2018 5:29 pm

Clock skew

Postby davepl » Tue Jul 25, 2023 9:58 pm

I've got an app (NightDriverLED.com) that relies on syncing time amongst multiple ESP32s via NTP. I've found they cam remain accurate to 1/1000000th of a second (0 microseconds) over 30 minutes, but sometimes, something happens that they shift several seconds, like 6.

I have no idea what causes it. I "fix" it by checking NTP time periodically, but it's still weird, and was wondering if anyone knows what might play havoc with the clock as reported by gettimeofday()?

Thanks!
Dave

davepl
Posts: 29
Joined: Wed Jun 27, 2018 5:29 pm

Re: Clock skew

Postby davepl » Fri Jul 28, 2023 5:33 pm

Thanks, ChatGPT!

But I'm embarassed to say my bug was a floating point precision issue. I had a stray float in my time_t -> double calculation, and when SECONDS was large enough, the fractional MICROSECONDS was being discarded, and was internally always zero. That's why it always matched!

So... my bug.

Thanks!
Dave

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

Re: Clock skew

Postby ESP_Sprite » Sun Jul 30, 2023 9:13 am

davepl wrote:
Fri Jul 28, 2023 5:33 pm
Thanks, ChatGPT!
Fwiw, that account (unsurprisingly) was a spambot, so I nuked it and its message.

Who is online

Users browsing this forum: Baidu [Spider], chegewara and 186 guests