[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4694: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4695: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4696: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
8devices Community - View topic - I2C RTC clock sincronization
www.8devices.com
View unanswered posts | View active topics It is currently 18 Apr 2024, 23:08



Reply to topic  [ 15 posts ]  Go to page 1, 2  Next
 I2C RTC clock sincronization 
Author Message

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
Profile
User avatar

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
Profile

Joined: 07 Jan 2012, 00:14
Posts: 50

_________________
Paco
www.tranquinet.com


04 Mar 2012, 18:07
Profile
User avatar

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
Profile

Joined: 07 Jan 2012, 00:14
Posts: 50

_________________
Paco
www.tranquinet.com


05 Mar 2012, 11:40
Profile

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
Profile

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
Profile

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
Profile

Joined: 04 Oct 2012, 11:57
Posts: 21
Hi,

why don't you simply use hwclock as described here?:
viewtopic.php?f=6&t=224

Michael


20 Dec 2012, 18:26
Profile

Joined: 18 Nov 2013, 18:44
Posts: 54


24 Feb 2014, 21:49
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 15 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Protected by Anti-Spam ACP Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.