I've gone through a plethora of sources and found it a little confusing with too much information hence posting this question.
Firstly, the scenario is, I've set up my PI-3B(jessie) with PCF8523t RTC. The PI will get connected to the internet very occasionally. So, therefore there are two questions I would like to get the answer for:
- I need to know if the modifications done below are correct (please suggest which are the required/redundant steps)
- What is best way to synchronise the Network time to the RTC whenever the internet comes up?
- [NEW] Is it required to disable the NTP service?
The problem was if the PI(when not connected to internet) was showing the correct time if booted after 10 minutes, but if booted after a day, there was incorrect time shown.
Below is the software version of the PI
pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
The following changes were made
- In the /boot/config.txt file
uncommented the 'dtparam=i2c_arm=on' and added 'dtoverlay=i2c-rtc,pcf8523'
- The following commands were run
apt-get -y remove fake-hwclock
rm /etc/cron.hourly/fake-hwclock
update-rc.d -f fake-hwclock remove
rm /etc/init.d/fake-hwclock
systemctl disable fake-hwclock
- Commented out the following lines in /lib/udev/hwclock-set
#if [ -e /run/systemd/system ] ; then
# exit 0
#fi
#/sbin/hwclock --rtc=$dev --systz --badyear
#/sbin/hwclock --rtc=$dev --systz
- Updated the (correct) system time into the hardware clock by
hwclock -w
- Added the below modules to the /etc/modules file
i2c-bcm2708
i2c-dev
i2c-pcf8523
- Edited the /etc/rc.local with the following lines
Ensured there is '#!/bin/bash' at the beginning of the script
sleep 2
pcf8523 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
( sleep 2; hwclock -s ) &
- Edited the /etc/default/hwclock with
HWCLOCKACCESS=yes
- Added the below as root's cronjob(done to sync the network time to RTC)
*/5 * * * * ntpdate 0.pool.ntp.org || ( hwclock --adjust; hwclock -s )