How to synchronize time between 2 WRT54G routers running on Openwrt?
This short tutorial documents the process that I took to synchronize time between 2 WRT54G routers.
I needed this function because I wanted to send log files out of the different nodes at the same time. Well, we all know that WRT54G routers don’t have on-board clocks so it’s hard to sync. But anyway, this actually works for me cause it makes it easier for me to time my experiments and run my cron jobs when they all start from 0. This is a complete trial and error thingy that yielded the results I wanted, so follow at your own risk.
Ok, enough crap, I gotta run some experiments later, so here goes:
Let’s call the router that you want to sync your time TO as S (I was thinking of server).
Let’s call the router that you want to sync as C (client in this case).
On S, perform the following 2 steps:
- Go download and install the Openntpd package. I used the web interface on the Openwrt.
- The next step is to open up /etc/ntpd.conf file and do this:
- Comment out the ping server portion if you want to keep your time as 0.
- Add in this: listen on <the_ip_address_of_S>
Apparently, we have to do this, so that S can listen for any requests coming in. If not I will get this “Connection Refused” error message when C tries to sync with S’s time.
On C, do the following:
- Download ntpclient package.
- To synchronise time, type in command line: ntpclient -s -h <the_ip_address_of_S>
Okies, presto! Type date on both routers and they should yield the same time. Enough for you to run experiments for a day 🙂
I am planning to use a cron job to execute C’s second instructions. Will do a cron job tutorial for dummies when there’s time.