Local Time Synchronisation on OpenWrt -KanKun Small K
This page contains an overview on how to configure time synchronization on a Kankun Small K running OpenWrt (also referred to as “time synchronization” in some countries).
Introductory Information
The Kankun Small K doesn’t contain a hardware clock, so the clock is reset each time the Kankun is rebooted. Even setting the clock to the correct time after a reboot isn’t sufficient, as I’ve found the clock drifts a lot over time (upto several minutes per hour).
The solution to this is to synchronize the clock when the Kankun is rebooted, and then to periodically synchronize it once the Kankun is running. its done by /etc/init.d/sysntpd
Time Synchronization to local time
Time Zone
Prior to performing time synchronization, you should ensure that the time zone is set correctly on your Kankun, by checking the value in /etc/TZ.
The default value stored on Kankun is
1 2 3 4 5 |
root@OpenWrt:~# cat /etc/TZ CST-8 root@OpenWrt:~# date Wed Nov 5 13:47:31 CST 2014 root@OpenWrt:~# |
I’m located in India (which is GMT-5:30), so I set the time zone using:
1 2 3 4 |
root@OpenWrt:~# echo CST-5:30 > /etc/TZ root@OpenWrt:~# date Wed Nov 5 11:18:21 CST 2014 root@OpenWrt:~# |
Confusingly, the offset in the TZ value specifies the time value you must add to the local time to get a UTC value, so this is positive if the local time zone is west of the Prime Meridian and negative if it is east. As a result, TZ must be set to GMT-8 for a timezone that is GMT+8.
Now the Kankun time zone is to your local time. temporary until reboot. as of my study till now from the /etc/init.d/boot
The timezone is updated to kernel from config file line number 20-22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
root@OpenWrt:~# cat /etc/init.d/boot #!/bin/sh /etc/rc.common # Copyright (C) 2006-2011 OpenWrt.org START=10 STOP=98 system_config() { local cfg="$1" local hostname conloglevel buffersize timezone zonename config_get hostname "$cfg" hostname 'OpenWrt' echo "$hostname" > /proc/sys/kernel/hostname config_get conloglevel "$cfg" conloglevel config_get buffersize "$cfg" buffersize [ -z "$conloglevel" -a -z "$buffersize" ] || dmesg ${conloglevel:+-n $conloglevel} ${buffersize:+-s $buffersize} config_get timezone "$cfg" timezone 'UTC' # echo "$timezone" > /tmp/TZ echo CST-5:30 > /etc/TZ config_get zonename "$cfg" zonename [ -n "$zonename" ] && [ -f "/usr/share/zoneinfo/$zonename" ] && ln -s "/usr/share/zoneinfo/$zonename" /tmp/localtime # apply timezone to kernel date -k } apply_uci_config() { sh -c '. /lib/functions.sh; include /lib/config; uci_apply_defaults' } start() { config_load system config_foreach system_config system } boot() { [ -f /proc/mounts ] || /sbin/mount_root [ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc [ -f /proc/net/vlan/config ] && vconfig set_name_type DEV_PLUS_VID_NO_PAD mkdir -p /var/run mkdir -p /var/log mkdir -p /var/lock mkdir -p /var/state mkdir -p /tmp/.uci chmod 0700 /tmp/.uci touch /var/log/wtmp touch /var/log/lastlog touch /tmp/resolv.conf.auto ln -sf /tmp/resolv.conf.auto /tmp/resolv.conf grep -q debugfs /proc/filesystems && /bin/mount -o noatime -t debugfs debugfs /sys/kernel/debug [ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe /sbin/kmodloader # allow wifi modules time to settle sleep 1 /sbin/wifi detect > /tmp/wireless.tmp [ -s /tmp/wireless.tmp ] && { cat /tmp/wireless.tmp >> /etc/config/wireless } rm -f /tmp/wireless.tmp apply_uci_config # temporary hack until configd exists /sbin/reload_config start # create /dev/root if it doesn't exist [ -e /dev/root -o -h /dev/root ] || { rootdev=$(awk 'BEGIN { RS=" "; FS="="; } $1 == "root" { print $2 }' < /proc/cmdline) [ -n "$rootdev" ] && ln -s "$rootdev" /dev/root } } root@OpenWrt:~# |
to change the time zone premenenantly by commenting the line and adding your local zone GMT. change the following lines in /etc/init.d/boot
Be Careful on your syntaxes .
1 2 3 |
config_get timezone "$cfg" timezone 'UTC' # echo "$timezone" > /tmp/TZ echo CST-5:30 > /etc/TZ |
5:30 for Indian Time you can substitute your own local GMT timings.
Now the timing Tasks and Delay tasks are synchronized to your local Time zones.
the Sheduled tasks can be found on
/etc/online.txt
Here with attached the schedule to Switch on the outdoor light on every day @ 18:01 and Switch Off @ 22:05 on all week days.
1 2 3 4 5 6 |
root@OpenWrt:/etc# cat online.txt VerInfo SW_VER3.1 HW_VER1.2 (null) (null) (null) (null) passwd nopassword (null) (null) (null) (null) (null) 279 y 2014-11-05-18:01:47 y 2014-11-05-22:05:47 y 1,2,3,4,5,6,7 1023 n 2014-11-05-11:58:41 y 4 n 0 root@OpenWrt:/etc# |
Happy hacking 😉