SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: [Solved] Time does not sync on Pi 3 and with official dongle

Mon Sep 11, 2017 12:26 pm

If you are using Jessie and the wifi only, you'll have problems with NTP if you don't use the iptables solution. Been there. Done that.

Newer Raspbian versions have fixed that. I've heard even Jessie has fixed that if you run these:

Code: Select all

sudo apt-get update
sudo apt-get upgrade
sudo rpi-update.

User avatar
DougieLawson
Posts: 36816
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: [Solved] Time does not sync on Pi 3 and with official dongle

Mon Sep 11, 2017 9:43 pm

I love your hack, but you may find that htpdate is easier.

http://www.vervest.org/htp/

It's in Raspbian (don't have a Ubuntu system to look at)

Code: Select all

Package: htpdate
Versions:
1.1.3-2 (/var/lib/apt/lists/mirrordirector.raspbian.org_raspbian_dists_stretch_main_binary-armhf_Packages) (/var/lib/apt/lists/archive.raspbian.org_raspbian_dists_stretch_main_binary-armhf_Packages)
 Description Language:
                 File: /var/lib/apt/lists/mirrordirector.raspbian.org_raspbian_dists_stretch_main_binary-armhf_Packages
                  MD5: 591296bd6b016838243fcf058ec7d163


Reverse Depends:
Dependencies:
1.1.3-2 - lsb-base (0 (null)) libc6 (2 2.4)
Provides:
1.1.3-2 -
Reverse Provides:
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

PlanB
Posts: 102
Joined: Tue Oct 28, 2014 6:44 am

Re: [Solved] Time does not sync on Pi 3 and with official dongle

Sun Oct 29, 2017 12:44 pm

I've got Jessie on a Pi0 whose only internet connection is a 3G modem that powers up briefly every 10 mins to squirt some data to a website. I'm in all all sorts of strife with ntp, ntpd, sntp, etc.

I've tried shutting down the automatic service (/etc/init.d/ntp stop) & running sntp -s google.com each time the modem comes on. This looks like it working

29 Oct 23:38:04 sntp[3036]: Started sntp
2017-10-29 23:38:10.924833 (-1000) -0.195425 +/- 0.000397 secs

but the pi always falls over within 24hrs with bad time stamps on the data packets. Could someone knowledgeable in this black art make a recommendation of the right way to go about this?

epoch1970
Posts: 4134
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: [Solved] Time does not sync on Pi 3 and with official dongle

Sun Oct 29, 2017 5:04 pm

PlanB wrote:
Sun Oct 29, 2017 12:44 pm
I've tried shutting down the automatic service (/etc/init.d/ntp stop) & running sntp -s google.com each time the modem comes on.
...
but the pi always falls over within 24hrs with bad time stamps on the data packets.
I'm not familiar with sntp, however https://www.eecis.udel.edu/~mills/ntp/html/sntp.html provides some interesting information on what options -M, -s and -S do.
Also, on my machine I don't see google.com and time.google.com resolve to the same hosts.

So I'd try "sntp -S time.google.com" each time the modem comes on. "-S" will step the clock, while "-s" adjusts it (too?) gradually.
And possibly later refine that with "sntp -S -s -M <some-value> time.google.com"
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

PlanB
Posts: 102
Joined: Tue Oct 28, 2014 6:44 am

Re: [Solved] Time does not sync on Pi 3 and with official dongle

Sun Oct 29, 2017 9:04 pm

sntp -s time.google.com seems to work as a clock adjuster, I'm just a bit unsure about if it keeps running or not after I've used it? It generally does the adjustment in just a few seconds.

ntpd -qg is definitely a one shot that I can use each modem power up but it takes at least a quarter of a minute to work, seems more interested in printing 'r' than resetting the time. I changed the servers in /etc/ntp.conf to local ones but that didn't improve the time it takes to sync, just got rid of the 'r's.

Do you know where these programs store the magic number that controls how often they try to sync when they are running continuously?

epoch1970
Posts: 4134
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: [Solved] Time does not sync on Pi 3 and with official dongle

Mon Oct 30, 2017 1:19 pm

sntp goes away after adjusting the clock, as far as I see. Use "ps waxu | grep sntp" or "pidof sntp" to check that.

I don't know how to force ntpd into a specific connection behaviour.

You could also use htpdate as dougielawson pointed above. It works over HTTP, it is accurate to the second AFAIK and it steps the clock. It is fast. With some web servers it does not work because some headers are missing, but in general it works.
If you install the default package it rather wants to stay and sync from time to time. I use it oneshot fashion in addition to ntpd, short rationale here.
In your case I suppose you don't care for a custom systemd unit, you could run something like "/usr/bin/htpdate -d -s -l -b www.pool.ntp.org 2>&1 >/dev/null" straight from your script.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
DougieLawson
Posts: 36816
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: [Solved] Time does not sync on Pi 3 and with official dongle

Mon Oct 30, 2017 1:25 pm

How about trying
sudo apt install ntp
sudo timedatectl set-ntp 1

first as NTP isn't installed by default on Raspbian Stretch.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

EvilBeeker
Posts: 3
Joined: Wed Jul 05, 2017 7:01 pm

Re: [Solved] Time does not sync on Pi 3 and with official dongle

Mon Oct 30, 2017 7:09 pm

DougieLawson wrote:
Mon Sep 11, 2017 9:43 pm
I love your hack, but you may find that htpdate is easier.

http://www.vervest.org/htp/

It's in Raspbian (don't have a Ubuntu system to look at)

Code: Select all

Package: htpdate
Thanks Doug, but that didn't work for me either -- but not for lack of trying. Everything I read said that htpdate might be the solution, so I tried it on both Jessie and Ubuntu Mate (fresh rebuilds). Eventually I gave up since no config I tried seemed to work. The cron-time-re-sync was the only solution I came up with that worked, as long as I put it out past 2-minutes. The units are fine if they are plugged into the LAN, then minute you take them off and on to wireless and reboot ntp just quits.

Return to “Troubleshooting”