Ensuring emonPi / emonBase time is synchronised with an NTP server

Continuing the discussion from EmonTX communication with RPi:

Not sure if there is a reason not to use the newer builtin time daemon. DietPi has a similar issue. I raised an issue for it Selecting 'Daemon + Drift' as ntp method does not set date · Issue #1208 · MichaIng/DietPi · GitHub

My Solution locally (assuming ntpd disabled)

  • Edit /etc/systemd/timesyncd.conf and enabled the time servers line.
  • Enable systemd-timesyncd systemctl enable systemd-timesyncd.service
  • Start systemd-timesyncd systemctl start systemd-timesyncd.service
  • Check timedatactl
[email protected]:/usr/sbin# timedatectl status
      Local time: Sun 2017-10-22 09:33:52 BST
  Universal time: Sun 2017-10-22 08:33:52 UTC
        RTC time: Thu 1970-01-01 00:34:09
       Time zone: Europe/London (BST, +0100)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2017-03-26 00:59:59 GMT
                  Sun 2017-03-26 02:00:00 BST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2017-10-29 01:59:59 BST
                  Sun 2017-10-29 01:00:00 GMT
  • Note NTP synchronized: no
  • Enable syncronization timedatectl set-ntp true

Reference used Time Synchronization with NTP and systemd although he intimates that ntp cannot be installed alongside systemd-timesyncd.

I’ve added a script ~/emonpi/ntp_update.sh:

This script will update NTP time. You can add a line to root crontab run run this script every 1hr to keep time updated:

$ sudo crontab -e

Add the line

0 * * * * /home/pi/emonpi/ntp_update.sh >> /var/log/ntp_update.log 2>&1

This change has been included in the latest emonSD release emonSD-26Oct17.

I’ve added a script ~/emonpi/ntp_update.sh:

This script will update NTP time. You can add a line to root crontab run run this script every 1hr to keep time updated:

$ sudo crontab -e

Add the line

0 * * * * /home/pi/emonpi/ntp_update.sh >> /var/log/ntp_update.log 2>&1

This change has been included in the latest emonSD release emonSD-26Oct17.

In a private communication, Bill Thomson said he’s replaced NPT with Chrony.
https://chrony.tuxfamily.org/comparison.html

He wrote “I discovered this during the process of adding hardware clocks to three of my RasPis. Puts the standard NTP package to shame.”

1 Like

My point is, why do this when there is a perfectly good system tool to do it for you?

What system are you referring to? I’m not familiar with Crony. NTP is pre installed on all emonPi’s and seems to work fine in my experience.

Not system, ‘system tool’ i.e. systemd-timesyncd.service

It is part of the move towards systemd and away from init and a number of builtin services have been developed; timesyncd being one of them.

Putting a cron job in is reinventing the wheel.

Sounds interesting. Could you explain the step by step setup if I was to
switch my emonPi?

  • sent from my mobile device

I put it in the original post under ‘My Solution Locally’

I’ve used it on a number of Pis both based on Jessie Lite and DietPi and all seem quite happy in keeping time.

What original post are you referring to? Please could you link me there.

First one in this conversation (repeated here) :smile:

My Solution locally (assuming ntpd disabled)

  • Edit /etc/systemd/timesyncd.conf and enabled the time servers line.
  • Enable systemd-timesyncd - systemctl enable systemd-timesyncd.service
  • Start systemd-timesyncd - systemctl start systemd-timesyncd.service
  • Check timedatactl
[email protected]:/usr/sbin# timedatectl status
      Local time: Sun 2017-10-22 09:33:52 BST
  Universal time: Sun 2017-10-22 08:33:52 UTC
        RTC time: Thu 1970-01-01 00:34:09
       Time zone: Europe/London (BST, +0100)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2017-03-26 00:59:59 GMT
                  Sun 2017-03-26 02:00:00 BST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2017-10-29 01:59:59 BST
                  Sun 2017-10-29 01:00:00 GMT
  • Note NTP synchronized: no
  • Enable syncronization - timedatectl set-ntp true

Reference used https://feeding.cloud.geek.nz/posts/time-synchronization-with-ntp-and-systemd/1 although he intimates that ntp cannot be installed alongside systemd-timesyncd.

Brian, Isn’t there an issue about using timesync on read-only file systems?
I understand that when it syncs time, it writes the data to /var/lib/systemd/clock which is hardcoded, and of course it can’t do if the system is RO.

Also… https://feeding.cloud.geek.nz/posts/time-synchronization-with-ntp-and-systemd/1 appears to be a dead link.
Try Time Synchronization with NTP and systemd

Paul

1 Like

Hi Paul,

You may well be right that it does not work on RO file systems which would then be a good reason for not using it (which was what I originally asked) :smile:

Personally anything logging data is running on a HDD so I don’t worry about using a RO file system.

Cheers.

Found an entry that supports this systemd-timesyncd - ArchWiki

Apparently Stretch has systemd-timesync service as the default …

https://www.raspberrypi.org/forums/viewtopic.php?t=192020