OpenWrt Forum Archive

Topic: wrt54g - cmos clock?!

The content of this topic has been archived on 24 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,
has the wrt54g a cmos clock? If this is the case how can I save system time to it?

         Thomas

it doesn't have a battery, so it will reset every time its rebooted.

I used the ntpclient package and added that to the bottom of /etc/init.d/rcS script as

/usr/bin/ntpclient -c 1 -s -h clock.redhat.com

then every reboot you are set to UTC

Why don't you use rdate?
It's already included in openwrt, and so you don't need to install a new package and waste space on your box.

If you are using ntpclient, consider using pool.ntp.org (or de.pool.ntp.org, au.pool.ntp.org etc) which will use DNS for a large pool of ntp servers, rather than hitting a specific ntp server (such as the redhat one mentioned above).

In the past some particular public servers have been overused to the extent that they are either now "proxied" or blocked for general use.

If you want to use ntpclient, you really should do it correctly.   ntp is not intended for one-shot setting of the clock rdate style... the clock on the WRT drifts rather fast, and using cron style daily settings will mess up log timestamps and other such actions as your clock will either go backwards several seconds, or skip forward several seconds.   my clock had drifted by FIVE MINUTES over a period of a week or two.

ok, what you SHOULD do with ntpclient.   first, fix busybox to include adjtimex, by editing sources/openwrt/busybox/busybox.config and adding ...
CONFIG_ADJTIMEX=y
and rebuild your openwrt (make clean in the busybox dir, then make in the top should be sufficient), and download this new openwrt, also `make ntpclient` and ipkg install it.

now, per the readme on ntpclient, run

# ntpclient -i 60 -c 30 -h 192.168.0.1 | tee /tmp/ntp.log

(replace that IP with your friendly neighborhood NTP server)

and then find rate.awk in the ntpclient source directory, and feed that .log file through it like...

$ awk -f rate.awk < ntp.log
delta-t 1500 seconds
delta-o 622716 useconds
slope 415.145 ppm
old frequency 0 ( 0 ppm)
new frequency 27206931 ( 415.145 ppm)

(I did this on my build computer rather than the WRT).

Now, take the last value displayed, like 27206931, and put this in /etc/init.d/S90ntpclient ...

#!/bin/sh
adjtimex -f 27206931                 
/usr/sbin/ntpclient -h 192.168.0.1 -s  
/usr/sbin/ntpclient -h 192.168.0.1 -l &

(again, replacing the IP's with the correct ones, and the adjtimex value with the one from rate.awk above)

*NOW* your clock should be right on the money, and ntpclient should run a phased lock loop to KEEP it that way.   Check it in a few days with `date` against that of your NTP reference server.

I have the following in one of the startup scripts.

while [ 1 ];do rdate -s time.foo.bar;sleep 3600;done &

This command will run rdate every hour to reset the system clock. Think of it as a poor man's ntpdate. I don't really need a clock which is 100% accurate all the time, so a little skip (the drift over an hour isn't that much) every hour is acceptable for me.

The advantage is that you can do this with a dead standard openwrt installation, no recompilation of busybox or extra package installations needed (ntpd, cron, etc). Oh, and for some reason ash seems to not send SIGHUP signals to background processes when the session ends, so this job will stay running until you kill it.

another way to run ntpdate regularly is to
add it to /etc/ppp/ip-up
(if you don't have/want crond)

Im my case I get reconnected after 24 hours
and need to redial. So my clock is updated
every 24 hours.

The discussion might have continued from here.