RTC in raspberry pi.

Rama Tito
Rama Tito used Ask the Experts™
on
Hi Experts,

i do have two raspberry pi, One as publisher and another one as a subscriber. It works on the local area network without internet. Data transmission and receiving, works fine and data storing into MariaDB also works fine. The issue is time. The router run locally without internet connection. If someone switch off or restart router, the system depend on router time which not synchronise online time.

To over this issue, i did add in RTC DC3231 in both raspberry with the following setup.

#!/bin/sh
# Reset the System Clock to UTC if the hardware clock from which it
# was copied by the kernel was in localtime.

dev=$1

#if [ -e /run/systemd/system ] ; then
# exit 0
#fi

if [ -e /run/udev/hwclock-set ]; then
    exit 0
fi

if [ -f /etc/default/rcS ] ; then
    . /etc/default/rcS
fi

# These defaults are user-overridable in /etc/default/hwclock
BADYEAR=no
HWCLOCKACCESS=yes
HWCLOCKPARS=
HCTOSYS_DEVICE=rtc0
if [ -f /etc/default/hwclock ] ; then
    . /etc/default/hwclock
fi

if [ yes = "$BADYEAR" ] ; then
    /sbin/hwclock --rtc=$dev --systz --badyear
    /sbin/hwclock --rtc=$dev --hctosys --badyear
else
    /sbin/hwclock --rtc=$dev --systz
    /sbin/hwclock --rtc=$dev --hctosys
fi

# Note 'touch' may not be available in initramfs
> /run/udev/hwclock-set

Open in new window


After i did this , its work on RTC time till someone reset or switch off the router. Upon router up, the raspberry pi picked up router time instead of RTC time. i have to do manually to switch to RTC time.

How i can over this, by saying just depend on RTC time only.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
nociSoftware Engineer
Distinguished Expert 2018

Commented:
Is there an ntp service active?   The please halt that.
( ps ax | grep ntp )
Rama TitoProgrammer

Author

Commented:
run on putty
In the attach picture i do get the result after typing "ps ax |grep ntp".
May i know what i am trying to acheive.
Software Engineer
Distinguished Expert 2018
Commented:
The right commands would have been: sudo service ntpd stop or sudo systemctl stop ntpd
ntpd is a (Network Time Protocol) daemon to get the times right, it can respond to multicast, or query specific servers.
Your description seemed to indicate response to multicast.  THe NTP daemon can also be used to use other time sources like GPS, DCF77, etc. etc.
There might be other tools doing more or less the same job as well.

you can check ps ax (process list output) for any process that might have anything to do with time

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial