Posts: 3
Joined: Wed Aug 03, 2016 3:49 pm

NTP synchronized: no

Thu Jan 10, 2019 1:06 am

Hi, I try to explain my problem as short as possible, thank you for kind help:
I've RasPI3 with RTC on I2C bus, I would like it consider it as default clock and use NTP (if internet available) every X hours to update RTC. It seems to be a quite hard work and sicerely I don't understand why Raspbian doesn't support this natively..

1) added to /boot/config.txt this: dtoverlay=i2c-rtc,ds3231
2) Reboot, RTC appears UU at i2cdetect -y 1
3) removed fake clock: fake clock sudo apt-get -y remove fake-hwclock AND sudo update-rc.d -f fake-hwclock remove
4) Edited /lib/udev/hwclock-set and added 3 times #:
#if [ -e /run/systemd/system ] ; then
# exit 0
5) reboot. After with timedatectl status I have "NTP synchronized: no", installed NTP by sudo apt install ntp and now I have "NTP synchronized: yes", but after next reboot again NO.
6) Solved with command "ntpq -c lpeer", after reboot again NO

Question1) Now why this happens? Why so difficult? Should I launc at every startup the command ntpq -c lpeer? There is any way to have "yes" without doing nothing?
QUestion 2) How can I be sure that NTP updates RTC time to time? I'm definealy not sure Raspbian do it automatically, how then can I force it and how can I schedule it?

I've found this script, I think it works ok but the execution needed to be scheduled somehow, can you help me? Thank you


# Location of logfile

# Set the maximum allowed difference in seconds between Hw-Clock and Sys-Clock

msgNoConnection="No connection to time-server"
msgConnection="Connection to time-server"

# Check for NTP connection
if ( ntpq -p | grep -q "^*" ); then
echo $msgConnection
echo "---------------------------------"

secHwClock=$(sudo hwclock --debug | grep "^Hw clock time" | awk '{print $(NF-3)}')
echo "HwClock: $secHwClock sec"

secSysClock=$(date +"%s")
echo "SysClock: $secSysClock sec"
echo "---------------------------------"


# Compute absolute value
if ( echo $secDiff | grep -q "-" ); then
secDiff=$(echo $secDiff | cut -d "-" -f 2)

echo "Difference: $secDiff sec"

msgDiff="HwClock difference: $secDiff sec"
if [ "$secDiff" -gt "$maxDiffSec" ] ; then
echo "---------------------------------"
echo "The difference between Hw- and Sys-Clock is more than $maxDiffSec sec."
echo "Hw-Clock will be updated"

# Update hwclock from system clock
sudo hwclock -w
msgDiff="$msgDiff --> HW-Clock updated."
if !(awk '/./{line=$0} END{print line}' $LOGFILE | grep -q "$msgConnection") || [ "$secDiff" -gt "$maxDiffSec" ]; then
echo $(date)": "$msgConnection". "$msgDiff >> $LOGFILE
# No NTP connection
echo $msgNoConnection
if !(awk '/./{line=$0} END{print line}' $LOGFILE | grep -q "$msgNoConnection"); then
echo $(date)": $msgNoConnection" >> $LOGFILE

Posts: 3
Joined: Wed Aug 03, 2016 3:49 pm

Re: NTP synchronized: no

Mon Jan 14, 2019 11:17 am

I kindly ask some help, thank you

Return to “Troubleshooting”