borpin
(Brian Orpin)
28 October 2017 14:48
1
Continuing the discussion from EmonTX communication with RPi :
And a general RPi question. After a longer power outage like today, when the RPi restarts the time is so wrong that NTP wont allow resync. I found a way to force it to resync using these commands:
sudo /etc/init.d/ntp stop
sudo ntpd -q -g
sudo /etc/init.d/ntp start
But is there any way of making it do this automatically.
I suspect that an additional contributor to the problem is that the internet router takes much longer to start than the RPi, so any solution needs to be able to be delayed by a few minutes after the RPi has restarted.
Yes, I have also noticed the issue when the Pi starts up faster than the router. So at bootup, NTP time does not work. I wonder if it would be worth running NTP update at regular intervals. Can anyone see any harm in this? I wonder what a good update rate would be? Once per hr?
It could be a bash script with the NTP stop/start commands that runs once per hr.
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 https://github.com/Fourdee/DietPi/issues/1208
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
root@DietPi:/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
:
committed 02:13PM - 20 Apr 17 UTC
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
:
committed 02:13PM - 20 Apr 17 UTC
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 .
We have just published an emonSD update: emonSD-26Oct2017.
[IMG_20171027_174103]
All emonPi / emonBase units purchased via the shop will be shipped with this version
This update is an incremental update with mainly security fixes including KRACK patch.
Existing users can apply the KRACK WAP vulnerability patch by following the instructions:
There is no need for existing users running emonSD-07Nov16 to upgrade to the new image. However if your running a version old then emonSD-07Nov16 I wo…
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
borpin
(Brian Orpin)
30 October 2017 22:28
4
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.
borpin
(Brian Orpin)
31 October 2017 21:59
6
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
borpin
(Brian Orpin)
31 October 2017 22:20
8
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.
borpin
(Brian Orpin)
1 November 2017 20:59
10
First one in this conversation (repeated here)
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
root@DietPi:/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
.
Paul
(Paul Reed)
1 November 2017 21:41
11
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
borpin
(Brian Orpin)
1 November 2017 22:05
12
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)
Personally anything logging data is running on a HDD so I don’t worry about using a RO file system.
Cheers.
borpin
(Brian Orpin)
16 November 2017 13:20
13
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