Author |
Message |
paco
Joined: 07 Jan 2012, 00:14 Posts: 50
|
Hello I have a carambola with ntpclient and it is working fine. I have added a I2C rtc clock and I would like to: - If ntp works fine set rtcclock - if ntp doesn't work get time rtc clock and set system time. This usually happend when there is not Internet connection. I use i2cget -y 0 0x68 reg b in order to get rtcclock values in BCD. reg is the register with diferent values 0 is for seconds, 1 for minutes, etc,.. I use RTC DS1307 it is cheap and easy to use. There are two main problems: - detect if there is a ntpclient or connection problem - setting and getting system time from i2cget Any idea about this? I could do it but I would like to get elegant and profesional advices. Thanks in advance.
_________________Paco www.tranquinet.com
|
03 Mar 2012, 17:10 |
|
|
David
Joined: 16 Dec 2011, 14:44 Posts: 105 Location: The Netherlands
|
You could write a (bash) shell script or a Lua script to handle something like this:
1. Ask the ntpclient whether the time synchronization was successful, or if that's not possible check the internet connection 2. If so, set the RTC time using i2cset 3. If not, get the time from RTC using i2get
Which programming and Linux experience do you have? That would be good to know for further recommendations.
_________________ | |
|
04 Mar 2012, 09:35 |
|
|
paco
Joined: 07 Jan 2012, 00:14 Posts: 50
|
_________________Paco www.tranquinet.com
|
04 Mar 2012, 18:07 |
|
|
David
Joined: 16 Dec 2011, 14:44 Posts: 105 Location: The Netherlands
|
Do you have any experience in Python? If not, I would consider skipping it for Carambola. The filesize is just way too big to fit on the 8MB of the Carambola. For bash scripting, I like this page: http://tldp.org/LDP/abs/html/
_________________ | |
|
04 Mar 2012, 18:24 |
|
|
paco
Joined: 07 Jan 2012, 00:14 Posts: 50
|
_________________Paco www.tranquinet.com
|
05 Mar 2012, 11:40 |
|
|
paco
Joined: 07 Jan 2012, 00:14 Posts: 50
|
Hello I have found this in OpenWRT
/etc/hotplug.d/iface/20-ntpclient). The script starts the daemon in 4 phases:
preliminary test - the script checks if the ntpclient is already running. drift - the scripts sets the specified drift in system clock. ntp server check phase - the script tests the reachability of the ntp servers (hosts) from config file (uses the ntpclient for this). The script only checks hosts where the specified interface (or inherited interface from ntpclient section) matches the interface that triggered hotplug.d or where no interface is specified at all. If no ntp server is reachable the script quits. operational phase - the ntpclient is started with the first reachable host and user configuration options (interval etc.) of polling and time adjustment
in the script 20-ntpclient the is a function
start_ntpclient() { config_foreach set_drift ntpdrift config_foreach check_server ntpserver [ -z "$SERVER" ] && exit 0 logger starting ntpclient $NTPC ${COUNT:+-c $COUNT} ${INTERVAL:+-i $INTERVAL} -s -l -D -p $PORT -h $SERVER 2> /dev/null }
I think this line should call a script to set system clock from i2c rtc device, instead of exit [ -z "$SERVER" ] && exit 0
I am right?
and after this line a line calling calling other script to set i2c rtc device from system clock. $NTPC ${COUNT:+-c $COUNT} ${INTERVAL:+-i $INTERVAL} -s -l -D -p $PORT -h $SERVER 2> /dev/null
I am right?
I don't know if there is a smartter way of doing this. I don't if modify 20-ntpclient is smart enough, I mean I am updating ntpclient configuration files.
I can do both scripts in python.
Thanks in advance.
_________________Paco www.tranquinet.com
|
05 Mar 2012, 15:01 |
|
|
paco
Joined: 07 Jan 2012, 00:14 Posts: 50
|
Hello A not very smart solution. in /etc/rtc.local a line /root/setSysClock.sh the above file as this content #!/bin/sh if ping -c1 google.com&> /dev/null; then echo "There is Internet connection: Setting RTC Clock"; python /root/setRtcClockFromSys.py; else echo "There is NOT Internet connection: Setting Sys Clock from RTC"; python /root/setSysClockFromRtc.py; fi Just did two python scripts. Well come all kind of advices. Thanks in advance
_________________Paco www.tranquinet.com
|
05 Mar 2012, 23:15 |
|
|
Zodiac69
Joined: 10 Jul 2012, 07:10 Posts: 25
|
Hi All
I know that this is an "old" post, but here is my 2cents... i am about to start with the hardware (DS1307) and see if i can get this working.
One the system is up and running and you are sure that the time should have been set, look at the system log: "Dec 19 15:43:25 OpenWrt user.notice root: starting ntpclient"
1. If the next line date and time is the same, Time is NOT set. 2. Read RTC, if local date and time delta is greater than "x", set time
Z69
|
20 Dec 2012, 07:31 |
|
|
rmike
Joined: 04 Oct 2012, 11:57 Posts: 21
|
Hi, why don't you simply use hwclock as described here?: viewtopic.php?f=6&t=224Michael
|
20 Dec 2012, 18:26 |
|
|
valent
Joined: 18 Nov 2013, 18:44 Posts: 54
|
|
24 Feb 2014, 21:49 |
|
|