dbsweng
Posts: 4
Joined: Tue Jul 12, 2022 8:07 am

Time Synchronisation on a standalone network

Fri Aug 05, 2022 5:38 pm

Hey guys,

I can't find the answer I'm looking for, most of the results I get are for people who are using GPS or other gadgets to get an accurate time.

I have a standalone network of headless (no gui - ssh only) pi4s.

Two of the pis record seagulls outside (yes, rock and roll lifestyle)

One pi hosts a wireless network and also automatically downloads the video files and puts them onto an external hdd.

There is no internet connection on this network; I intentionally keep this network disconnect from our home network to stop the download job slowing the whole network down. Whenever I want the files, I plug a flash drive in to the host pi and copy them (I log into the pi remotely and use the cp command).

The ftp server on the pi sometimes dies, and a simple reset of the ftp service does not fix it, one must reboot the pi to get everything going again. This happens every other day, it's a common experience, nobody seems to have a solution.

So I wrote a script to reboot periodically, it's not a big deal if I miss a few frames of video. However the problem is that the time starts to drift as the pi loses a few seconds every reboot.

So I want to have the two video recording pis to set their time based on the host pi's time, it's not super accurate but it's close enough just to have my videos roughly correctly timed. Does anyone know how I could do that?

User avatar
rpdom
Posts: 20380
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Time Synchronisation on a standalone network

Fri Aug 05, 2022 6:37 pm

Add an RTC module to the Pi. The DS3231 ones are fairly cheap and accurate. You could put a module on every Pi, or just have one and run it as an NTP server to the rest on the network.

Or, as you say you don't want additional hardware, you could just make the master Pi the NTP server. But I would recommend a proper RTC to keep the time accurate to real time.
Unreadable squiggle

MiscBits
Posts: 951
Joined: Wed Jan 27, 2021 12:48 pm

Re: Time Synchronisation on a standalone network

Fri Aug 05, 2022 8:26 pm

I assume you have a separate switch etc for the Pi and not sharing access points so why not have one of the Pis connect to your normal network via the other interface network and get the time and act as the NTP server for the 'other' network?

Normal network routine will keep the video traffic on its own network...

As an ex-twitcher (and ex-dawn counter of wading birds fir the RSPB) I see nothing odd about seagull videos :D
Old sig removed given the current world situation. Please wish / pray / work for a peaceful world.

ejolson
Posts: 9774
Joined: Tue Mar 18, 2014 11:47 am

Re: Time Synchronisation on a standalone network

Fri Aug 05, 2022 8:45 pm

dbsweng wrote:
Fri Aug 05, 2022 5:38 pm
Hey guys,

I can't find the answer I'm looking for, most of the results I get are for people who are using GPS or other gadgets to get an accurate time.

I have a standalone network of headless (no gui - ssh only) pi4s.

Two of the pis record seagulls outside (yes, rock and roll lifestyle)

One pi hosts a wireless network and also automatically downloads the video files and puts them onto an external hdd.

There is no internet connection on this network; I intentionally keep this network disconnect from our home network to stop the download job slowing the whole network down. Whenever I want the files, I plug a flash drive in to the host pi and copy them (I log into the pi remotely and use the cp command).

The ftp server on the pi sometimes dies, and a simple reset of the ftp service does not fix it, one must reboot the pi to get everything going again. This happens every other day, it's a common experience, nobody seems to have a solution.

So I wrote a script to reboot periodically, it's not a big deal if I miss a few frames of video. However the problem is that the time starts to drift as the pi loses a few seconds every reboot.

So I want to have the two video recording pis to set their time based on the host pi's time, it's not super accurate but it's close enough just to have my videos roughly correctly timed. Does anyone know how I could do that?
I would force the network time protocol to recognize the free-running internal clock of the Pi you want to use for the reference as a stratum time source.

I used to know how to do this using the traditional ntpd time server. It is possible systemd has assimilated that function. If so, you may need to disable the built-in ntp of systemd before proceeding.

User avatar
rpdom
Posts: 20380
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Time Synchronisation on a standalone network

Fri Aug 05, 2022 8:52 pm

ejolson wrote:
Fri Aug 05, 2022 8:45 pm
I used to know how to do this using the traditional ntpd time server. It is possible systemd has assimilated that function. If so, you may need to disable the built-in ntp of systemd before proceeding.
From what I can remember, if ntpd is installed and configured systemd will not run its time services.
Unreadable squiggle

Doug_
Posts: 195
Joined: Tue Oct 08, 2019 6:40 pm

Re: Time Synchronisation on a standalone network

Sat Aug 06, 2022 2:22 am

To set the date and time on a remote stand alone pi I use the command from a Linux machine that has the correct time:

Code: Select all

ssh pi@target sudo date -s$(date -Ins)
This does not give microsecond accuracy but does what I think you are looking for. The time could then be transferred to your slaves in a similar manner within a suitable script.

Hope this helps, I like your project too btw.

User avatar
rpdom
Posts: 20380
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Time Synchronisation on a standalone network

Sat Aug 06, 2022 9:11 am

Doug_ wrote:
Sat Aug 06, 2022 2:22 am
To set the date and time on a remote stand alone pi I use the command from a Linux machine that has the correct time:

Code: Select all

ssh pi@target sudo date -s$(date -Ins)
This does not give microsecond accuracy but does what I think you are looking for. The time could then be transferred to your slaves in a similar manner within a suitable script.

Hope this helps, I like your project too btw.
I'd turn that script around and run it on each Pi at boot, after the network has settled, to get the time from another Pi on that isolated network.

Code: Select all

sudo date $(ssh pi@target 'date +%m%d%H%M%Y.%S')
That way each Pi will set its time to match those on the network after a reboot. You could add some logic with a ping to detect which Pi is active and maybe use a remote uptime to check it hasn't just booted and showing the wrong time.
Unreadable squiggle

epoch1970
Posts: 7994
Joined: Thu May 05, 2016 9:33 am
Location: France

Re: Time Synchronisation on a standalone network

Sat Aug 06, 2022 10:38 am

Really, why not use NTP??
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
rpdom
Posts: 20380
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Time Synchronisation on a standalone network

Sat Aug 06, 2022 12:18 pm

epoch1970 wrote:
Sat Aug 06, 2022 10:38 am
Really, why not use NTP??
Indeed. I was thinking after posting that last comment that we are pretty much re-inventing NTP. :lol:
Unreadable squiggle

Return to “Networking and servers”