Page 1 of 1

Clock skew

Posted: Tue Jul 25, 2023 9:58 pm
by davepl
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

Re: Clock skew

Posted: Fri Jul 28, 2023 5:33 pm
by davepl
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

Re: Clock skew

Posted: Sun Jul 30, 2023 9:13 am
by ESP_Sprite
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.