Time sync and custom scripts

Hi,

I have quite a few RUT955’s (and a few 956’s) that run a custom application. This is working OK, but one issue I face is time synchronisation. My application requires an accurate clock; currently I’m relying on NTP for this, but it would be great if I could use other time sources (i.e. GPS) so that the application can gather data without a network connection (coverage is often unreliable, and data is queued until the connection comes up, but needs to be timestamped). I’m not sure if there is a way to detect when the router has updated it’s clock with a reliable time from GPS?

My current approach is the script below (this is run from the startup script e.g. (/mnt/mmcblk0p1/scriptname.sh > /mnt/mmcblk0p1/script.log 2>&1 )&). This works (and has been reliable) but requires a network connection (because it relies on NTP). If there is no connection then the script will block until the connection comes up and a time is acquired via NTP.

Ideally I’d like the application to start as soon as there is an accurate time (whether from NTP or GPS), so am posting this in the hope that someone else has a better approach! (suggestions for better ways of waiting for an NTP time would also be appreciated).

Thanks,
Matt

# We default to 0.pool.ntp.org (should be overridden by router config)
ntpServer="0.pool.ntp.org"

# Retrieve config (updates ntpServer with value from config - if any) 
# Functions copied from built in scripts and modified to work..
. $IPKG_INSTROOT/lib/functions.sh
config_load ntpclient

store_server() {
   config_get hostname $1 hostname
   [ -z "$hostname" ] && return
   ntpServer=$hostname
}

handle_ntp_config() {
        config_foreach store_server ntpserver
}

config_foreach handle_ntp_config ntpclient

# IMPORTANT: The below only works with the RUT9XX firmware. With earlier versions it will never exit!
# We stop the ntpclient service because having it running twice might cause issues!
# Note: If network is unavailable then ntpclient terminates immediately ("connect: Network unreachable") but does set returncode to 1 (successful = 0)
/etc/rc.d/S99ntpclient stop
echo "ntp: starting"
while !(ntpclient -h $ntpServer -g 1000000 -i 30 -s); do sleep 60; done
echo "ntp: done"
/etc/rc.d/S99ntpclient start

echo "starting app"
/mnt/mmcblk0p1/app

This topic was automatically closed after 15 days. New replies are no longer allowed.