option.ntpsync

Recurrent H/W and software problems
Post Reply
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

option.ntpsync

Post by BeanieBots »

First off, a big thankyou to cicciob for producing this wonderful Annex RDS. Without it, non-programmers like myself would be up the creek without a paddle.
I'd also like to thank Electroguard for all his tips examples and 'gotchas', AndyGadget (a blast from the past on PICAXE forum) and PeterN all who have answered nearly all my questions over the last few years without me even having to have registered on this forum!
At long last, I've got around to posting. Hopefully I'll be able to contribute some projects later.

Anyway, my question.
I have a plethora of ESP8266s and 32s, many of which run for months on end without any issues except for time keeping.
Most of them drift by a minute or so each week.
I have set a time zone and NTPserver in the config page but the only way to 'correct' the drifted time is either a power reset or enter 'option.ntpsync' into the immediate command box.
Should I have a 'option.ntpsync' line in my code that gets run periodically, say every day at midnight, or have I missed something to make this happen automatically.
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: option.ntpsync

Post by Electroguard »

Just set up a 24hr timer to execute OPTION.NTPSYNC once every night on all the devices.
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: option.ntpsync

Post by BeanieBots »

OK, thanks for the quick reply. I'll do that. I had it in the back of my head that it was an automatic background task.
User avatar
cicciocb
Site Admin
Posts: 1900
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1271 times
Contact:

Re: option.ntpsync

Post by cicciocb »

I never noticed this problem. The update should be automatic ( each hour). I'll check it..
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: option.ntpsync

Post by BeanieBots »

Just so that you are aware, most of my devices are still running 1.41 beta 5.
Other than a slight drift in time, they just work, so never felt the need to upgrade.
I'll try to upgrade them over the next few days to the latest and see if the problem still exists.

Edit: Further information, in case it's relevant.
Time zone "GMT0BST,M3.5.0/1,M10.5.0"
NTP server "0.uk.pool.ntp.org"
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: option.ntpsync

Post by Electroguard »

the only way to 'correct' the drifted time is either a power reset or enter 'option.ntpsync'
It does sound like some of your devices are not regularly syncing to your specified time server, but you seemed to think that immediately entering option.ntpsync does actually sync time ok, therefore doing it nightly should keep them synced.

BUT ... I suspect that (at least some of) your devices are not actually syncing to your specified time server - which if so, might not be obvious or apparent.

I vaguely remember a long time ago, either failing to create my own intranet time-server, or my devices not syncing to it.
Because my devices are on an isolated subnet I ended up using an RTC module on 1 device that acts as a time server which responds with its time and date to any newly connecting devices by UDP broadcasts, so all other devices also sync up to the broadcast time and date. It works well, and I have an option.ntpsync webpage button on the time-server which I need to use twice a year to sync to internet time whenever summertime changes.
But none of my many devices specifies a time server in the NTP Server field.

So if your devices may not be connecting to your specified time-server, you might want to try leaving your NTP Server fields blank so that they access the default NTP servers, cos they can't do any worse, but they might actually do better.
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: option.ntpsync

Post by BeanieBots »

Thanks for the tips and I'll try them. Problem with testing is that it takes quite a while to accumulate even a few seconds of drift.
Maybe I can set a 'false' time via the direct command box and wait to see if it syncs over the next hour.
I've just had a browse around some of the other devices and some are set to "0.uk.pool.ntp.org" others to "1.uk.pool.ntp.org". Neither seem to sync.
It was so long ago now I can't remember why the difference but I think it was because I noticed an issue when they were originally set up.
It was only recently when I added some ESPnow messages coming from a distant sensor that sometimes failed to send that I added time stamps to the data and noticed that there were differences of a few minutes which didn't make sense as the transmissions were every 10 minutes!

Past my bedtime now, out all day tommorow and booked in for some horrendous surgery Tues, so I'll try and get your suggestions checked out between now and then because I doubt I'll be up for much for a few weeks after Tues :cry:
User avatar
cicciocb
Site Admin
Posts: 1900
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1271 times
Contact:

Re: option.ntpsync

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Thu Jul 07, 2022 8:02 pm Just so that you are aware, most of my devices are still running 1.41 beta 5.
Other than a slight drift in time, they just work, so never felt the need to upgrade.
I'll try to upgrade them over the next few days to the latest and see if the problem still exists.

Edit: Further information, in case it's relevant.
Time zone "GMT0BST,M3.5.0/1,M10.5.0"
NTP server "0.uk.pool.ntp.org"
It is not required to enter any NTP server as, by default, it use pool.ntp.org (if I remember well).
So just put an empty space inside the NTP server textbox
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: option.ntpsync

Post by BeanieBots »

OK, so I managed to get some testing done.
In all cases:-
1. The time was deliberately set to be 5 minutes slow by using SETTIME via the immediate panel
2. NTP server was tried blank, with 0.uk.pool.ntp.uk and 1.uk.ntp.uk (It is no longer possible to set this with latest ESP32 firmware).
3. Time was periodically check using TIME$ via 'get variables'
4. All tests were performed on 2 off ESP32s and 2 off ESP2866s which yielded consistent results.
5. Firmware was uploaded using AnnexToolkit V1.22
6. Each unit was tested over a period of 3 hours.

Results:-
ESP32 with Annex32 WiFi 1.41 beta 5.
Time remained 5min out. Became correct in all cases with option.ntpsync entered in immediate panel and/or a power cycle.
ESP32 with Annex32 WiFi BLE CAN 1.44.2
Time corrected within about 1 hour as expected.

ESP2866 with Annex WiFi 1.42.3
Time corrected within about 1 hour as expected.

ESP2866 with Annex WiFi 1.44.2
Time corrected within about 1 hour as expected.

So, in conclusion, it would appear that only the old beta 5 firmware on ESP32 has an issue with not updating the time.
I will upgrade all my older devices and this issue should go away.
Thanks to both of you for your help and support with this.
Post Reply