Page 1 of 1

(Solved) Time sync problem

Posted: Sat Sep 08, 2018 11:48 am
by RPIWnivarna
Hi,

I have had this problem with the pis not syncing time properly, all posts on forums are form years ago that I have found and really want to get this solved.

I want to make my wife a watering pi but need the clock to be correct for watering times.

Even when I freshly configure the localisation settings, it still is 2 hrs slow. so I have to manually set with:

sudo date -s 'Sun Sep 09 07:46:47 AEST 2018'

I even found a google sync I thought I could run in cron but it still gives it in utc

sudo date -s "$(curl -s --head http://google.com.au | grep ^Date: | sed 's/Date: //g')"

I have a pi hole set up, could that be doing it? Could this be a bug for my time zone? Can any Aussies on AEST confirm?

Alternatively I suppose I could just train my wife to convert to utc :)

Re: Time sync problem

Posted: Sat Sep 08, 2018 4:23 pm
by DirkS
If you're on Raspbian Stretch can you run

Code: Select all

timedatectl
systemctl status systemd-timesyncd.service
and post the output here.

Re: Time sync problem

Posted: Mon Sep 10, 2018 6:17 am
by RPIWnivarna
Thanks for your help DirkS

timedatectl
Local time: Sun 2018-09-09 12:25:13 AEST
Universal time: Sun 2018-09-09 02:25:13 UTC
RTC time: n/a
Time zone: Australia/Melbourne (AEST, +1000)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no

● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/systemd-timesyncd.service.d
└─disable-with-time-daemon.conf
Active: active (running) since Sun 2018-09-09 12:20:24 AEST; 7min ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 192 (systemd-timesyn)
Status: "Connecting to time server 178.63.9.212:123 (1.debian.pool.ntp.org)."
CGroup: /system.slice/systemd-timesyncd.service
└─192 /lib/systemd/systemd-timesyncd

Sep 09 12:24:54 squid systemd-timesyncd[192]: Timed out waiting for reply from 78.46.253.198:123 (2.debian.pool.ntp.org).
Sep 09 12:25:04 squid systemd-timesyncd[192]: Timed out waiting for reply from 193.141.27.1:123 (3.debian.pool.ntp.org).
Sep 09 12:25:14 squid systemd-timesyncd[192]: Timed out waiting for reply from 176.221.42.125:123 (3.debian.pool.ntp.org).
Sep 09 12:25:25 squid systemd-timesyncd[192]: Timed out waiting for reply from 131.188.3.220:123 (3.debian.pool.ntp.org).
Sep 09 12:25:35 squid systemd-timesyncd[192]: Timed out waiting for reply from 144.76.60.190:123 (3.debian.pool.ntp.org).
Sep 09 12:26:50 squid systemd-timesyncd[192]: Timed out waiting for reply from 212.18.3.19:123 (0.debian.pool.ntp.org).
Sep 09 12:27:00 squid systemd-timesyncd[192]: Timed out waiting for reply from 146.0.32.144:123 (0.debian.pool.ntp.org).
Sep 09 12:27:10 squid systemd-timesyncd[192]: Timed out waiting for reply from 144.76.76.107:123 (0.debian.pool.ntp.org).
Sep 09 12:27:20 squid systemd-timesyncd[192]: Timed out waiting for reply from 78.46.60.40:123 (0.debian.pool.ntp.org).
Sep 09 12:27:31 squid systemd-timesyncd[192]: Timed out waiting for reply from 213.172.105.106:123 (1.debian.pool.ntp.org).

Re: Time sync problem

Posted: Mon Sep 10, 2018 6:32 am
by PhatFil
looks like your not establishing a connection with the ntp servers set so perhaps check for local reliable ntp servers and set accordingly.
https://raspberrypi.stackexchange.com/q ... ch-systems

Re: Time sync problem

Posted: Mon Sep 10, 2018 9:57 am
by RPIWnivarna
Ok, took last suggestion and used googles ntp server

sudo nano /etc/systemd/timesyncd.conf

#NTP=216.239.35.0
FallbackNTP=0.arch.pool.ntp.org 1.arch.pool.ntp.org 2.arch.pool.ntp.org 3.arch.$
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048

● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/systemd-timesyncd.service.d
└─disable-with-time-daemon.conf
Active: active (running) since Sun 2018-09-09 15:39:58 AEST; 25min ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 180 (systemd-timesyn)
Status: "Idle."
CGroup: /system.slice/systemd-timesyncd.service
└─180 /lib/systemd/systemd-timesyncd

Sep 09 16:03:22 squid systemd-timesyncd[180]: Timed out waiting for reply from 78.46.53.2:123 (1.arch.pool.ntp.org).
Sep 09 16:03:32 squid systemd-timesyncd[180]: Timed out waiting for reply from 85.10.240.253:123 (1.arch.pool.ntp.org).
Sep 09 16:03:43 squid systemd-timesyncd[180]: Timed out waiting for reply from 193.175.73.151:123 (2.arch.pool.ntp.org).
Sep 09 16:03:53 squid systemd-timesyncd[180]: Timed out waiting for reply from 213.202.247.29:123 (2.arch.pool.ntp.org).
Sep 09 16:04:03 squid systemd-timesyncd[180]: Timed out waiting for reply from 217.91.44.17:123 (2.arch.pool.ntp.org).
Sep 09 16:04:14 squid systemd-timesyncd[180]: Timed out waiting for reply from 78.46.204.247:123 (2.arch.pool.ntp.org).
Sep 09 16:04:24 squid systemd-timesyncd[180]: Timed out waiting for reply from 213.202.247.29:123 (3.arch.pool.ntp.org).
Sep 09 16:04:35 squid systemd-timesyncd[180]: Timed out waiting for reply from 185.11.138.90:123 (3.arch.pool.ntp.org).
Sep 09 16:04:45 squid systemd-timesyncd[180]: Timed out waiting for reply from 129.70.132.32:123 (3.arch.pool.ntp.org).
Sep 09 16:04:55 squid systemd-timesyncd[180]: Timed out waiting for reply from 94.16.116.137:123 (3.arch.pool.ntp.org).
[email protected]:~ $ timedatectl
Local time: Sun 2018-09-09 16:07:14 AEST
Universal time: Sun 2018-09-09 06:07:14 UTC
RTC time: n/a
Time zone: Australia/Melbourne (AEST, +1000)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no

So no progress.

Re: Time sync problem

Posted: Mon Sep 10, 2018 10:33 am
by DirkS
Is there something in your network that blocks port 123?

Re: Time sync problem

Posted: Tue Sep 11, 2018 12:40 am
by RPIWnivarna
Is there a reason pi hole would block port 123? I haven't touched the config of that, so it is all the default settings, I will disable it when I get home to test that one out.

Re: Time sync problem

Posted: Tue Sep 11, 2018 6:29 am
by RPIWnivarna
Checked the admin interface:

Top Permitted Domains
Domain Hits Frequency
0.irobot.pool.ntp.org 473
1.irobot.pool.ntp.org 470
2.irobot.pool.ntp.org 460
3.irobot.pool.ntp.org 459
graph.facebook.com 189
www.google.com 136
query.yahooapis.com 132
2.debian.pool.ntp.org 131
3.debian.pool.ntp.org 117
android.clients.google.com 116

So it says it allows them through, will start pi with pihole disabled as test

[email protected]:~ $ timedatectl
Local time: Sun 2018-09-09 17:20:04 AEST
Universal time: Sun 2018-09-09 07:20:04 UTC
RTC time: n/a
Time zone: Australia/Melbourne (AEST, +1000)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no
[email protected]:~ $ systemctl status systemd-timesyncd.service>output
Warning: systemd-timesyncd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[email protected]:~ $ cat output
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/systemd-timesyncd.service.d
└─disable-with-time-daemon.conf
Active: active (running) since Sun 2018-09-09 17:17:10 AEST; 3min 12s ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 241 (systemd-timesyn)
Status: "Connecting to time server 46.163.88.237:123 (1.arch.pool.ntp.org)."
CGroup: /system.slice/systemd-timesyncd.service
└─241 /lib/systemd/systemd-timesyncd

Sep 09 17:18:42 squid systemd-timesyncd[241]: Timed out waiting for reply from 85.236.36.4:123 (3.debian.pool.ntp.org).
Sep 09 17:18:53 squid systemd-timesyncd[241]: Timed out waiting for reply from 78.47.226.109:123 (3.debian.pool.ntp.org).
Sep 09 17:19:03 squid systemd-timesyncd[241]: Timed out waiting for reply from 5.9.80.113:123 (3.debian.pool.ntp.org).
Sep 09 17:19:14 squid systemd-timesyncd[241]: Timed out waiting for reply from 193.141.27.1:123 (0.arch.pool.ntp.org).
Sep 09 17:19:24 squid systemd-timesyncd[241]: Timed out waiting for reply from 141.30.228.4:123 (0.arch.pool.ntp.org).
Sep 09 17:19:34 squid systemd-timesyncd[241]: Timed out waiting for reply from 185.233.106.45:123 (0.arch.pool.ntp.org).
Sep 09 17:19:44 squid systemd-timesyncd[241]: Timed out waiting for reply from 94.130.183.105:123 (0.arch.pool.ntp.org).
Sep 09 17:19:55 squid systemd-timesyncd[241]: Timed out waiting for reply from 138.68.126.106:123 (1.arch.pool.ntp.org).
Sep 09 17:20:05 squid systemd-timesyncd[241]: Timed out waiting for reply from 131.188.3.221:123 (1.arch.pool.ntp.org).
Sep 09 17:20:15 squid systemd-timesyncd[241]: Timed out waiting for reply from 165.227.159.15:123 (1.arch.pool.ntp.org).

Had to output to file, as it goes nuts as naked command for some reason

Re: Time sync problem

Posted: Tue Sep 11, 2018 6:46 am
by PhatFil
just thinking aloud here but how sophisticated is your network router/adsl or cable modem has it got a NTP setting?? if so it might be 'smart' and expect you to point to it and not a remote server?

can you ping those ntp addys ?

one of the outputs lists time outs, is there a significant lag on your network connection ? would bumping up the timeouts have any impact?

Re: Time sync problem

Posted: Tue Sep 11, 2018 7:53 am
by epoch1970
NTP is a separate protocol from HTTP, I suppose your setup blocks 123/udp which should be allowed in an out of the Pi and the router.
AFAIK you can install htpdate on the Pi. This package uses the server's HTTP header contents to set system time, so it should be compliant with your current setup. (Not all websites send back enough information, if you get no date back try to specify another site.)
The date obtained is less accurate than from NTP servers, but it should be "good enough".

Re: Time sync problem

Posted: Tue Sep 11, 2018 11:25 am
by RPIWnivarna
And it is fixed.

[email protected]:~ $ date
Tue 11 Sep 14:06:21 AEST 2018
[email protected]:~ $ sudo apt install htpdate
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
htpdate
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 17.3 kB of archives.
After this operation, 53.2 kB of additional disk space will be used.
Get:1 http://raspbian.melbourneitmirror.net/raspbian stretch/main armhf htpdate armhf 1.1.3-2 [17.3 kB]
Fetched 17.3 kB in 2s (8,033 B/s)
Selecting previously unselected package htpdate.
(Reading database ... 40320 files and directories currently installed.)
Preparing to unpack .../htpdate_1.1.3-2_armhf.deb ...
Unpacking htpdate (1.1.3-2) ...
Setting up htpdate (1.1.3-2) ...
Processing triggers for systemd (232-25+deb9u4) ...
Processing triggers for man-db (2.7.6.1-2) ...
[email protected]:~ $ date
Tue 11 Sep 21:18:21 AEST 2018


Thank you epoch1970, that has instantly solved my problem that has been a thorn in my side for many months, I have already installed it on all my pis,

Thank you to all that have pitched in on this problem too.

Re: (Solved) Time sync problem

Posted: Wed Sep 12, 2018 10:53 am
by PhatFil
Glad to hear its sorted..

Re: (Solved) Time sync problem

Posted: Wed Mar 27, 2019 11:59 am
by eAL
Thanks guys this worked fine for me, too!
Struggeld also since september 2018 with this issue and used an RTC since, NO MORE!