0

Raspberry Pi GPS Stratum 1 NTP Server
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

Re: Raspberry Pi GPS Stratum 1 NTP Server

by CTrek on Mon Mar 26, 2018 10:52 am

Has anybody by chance made a start to finish guide of how to get the Adafruit Ultimate GPS to update the Rpi 3's system clock while connected via USB? That would be ideal but I'd settle for a SQL connection to the latest GPS time. I just need somewhat close date times for database logging and Raspbian and their native NTP is nowhere close to getting it done.

I tried to follow this thread but I think I just made a mess of things in the attempt :(

CTrek
 
Posts: 5
Joined: Fri Feb 09, 2018 2:18 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by phipac on Thu May 17, 2018 2:01 pm

[quote="gtj"]Ok, Here's the process.

  • Start with a fresh Raspian SD card.
  • In the initial configuration menu...
    • select Expand Filesystem.
    • select Advanced, SSH and enable it.
    • select Advanced, Serial, Answer No for a login shell.
    • select Finish and reboot.
  • Immediately after reboot...
      Code: Select all | TOGGLE FULL SIZE
      $ sudo apt-get update
      $ sudo apt-get dist-upgrade
      $ sudo rpi-update
      $ sudo apt-get install libcap-dev libssl-dev pps-tools

    • Add dtoverlay=pps-gpio,gpiopin=4 to the end of /boot/config.txt
    • Add pps-gpio to the end of /etc/modules
    • Reboot
    • After the reboot verify that /dev/pps0 exists.

Seems like this is pretty straightforward. However, after trying four times on a Pi3, I cannot get /dev/pps0 to show up. Is there something that has changed with newer kernels or firmware? Has anyone else solved this? I scoured this thread and nothing looks like it is what I need. After completing the above steps, this is what is in /dev
Code: Select all | TOGGLE FULL SIZE
autofs         console          full       hwrng    loop1  loop7             mmcblk0p1           null  ram10  ram2  ram8     serial1  tty    tty13  tty19  tty24  tty3   tty35  tty40  tty46  tty51  tty57  tty62    ttyprintk  vcio    vcs4   vcsa3  watchdog
block          cpu_dma_latency  fuse       initctl  loop2  loop-control      mmcblk0p2           ppp   ram11  ram3  ram9     shm      tty0   tty14  tty2   tty25  tty30  tty36  tty41  tty47  tty52  tty58  tty63    ttyS0      vc-mem  vcs5   vcsa4  watchdog0
btrfs-control  cuse             gpiochip0  input    loop3  mapper            mqueue              ptmx  ram12  ram4  random   snd      tty1   tty15  tty20  tty26  tty31  tty37  tty42  tty48  tty53  tty59  tty7     uhid       vcs     vcs6   vcsa5  zero
bus            disk             gpiochip1  kmsg     loop4  mem               net                 pts   ram13  ram5  raw      stderr   tty10  tty16  tty21  tty27  tty32  tty38  tty43  tty49  tty54  tty6   tty8     uinput     vcs1    vcsa   vcsa6
cachefiles     fb0              gpiochip2  log      loop5  memory_bandwidth  network_latency     ram0  ram14  ram6  rfkill   stdin    tty11  tty17  tty22  tty28  tty33  tty39  tty44  tty5   tty55  tty60  tty9     urandom    vcs2    vcsa1  vcsm
char           fd               gpiomem    loop0    loop6  mmcblk0           network_throughput  ram1  ram15  ram7  serial0  stdout   tty12  tty18  tty23  tty29  tty34  tty4   tty45  tty50  tty56  tty61  ttyAMA0  vchiq      vcs3    vcsa2  vhci


Appreciate the help!

phipac
 
Posts: 2
Joined: Thu May 17, 2018 1:55 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by W8FG on Sat May 26, 2018 10:01 am

I have been through these instructions at least 3 times now, starting with a fresh load of Raspbian each time. There are lots of errors and I don't even begin to know how to fix them.

I don't understand why one of the commands in the list is to uninstall NTP with apt-get , aren't we wanting NTP as part of the end picture?

I have passed all the GPS tests just wonder why in GPSMON the one field with NOTHING is PPS


Thanks,
Seth

W8FG
 
Posts: 4
Joined: Sat Sep 09, 2017 10:02 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by phipac on Mon May 28, 2018 11:40 am

W8FG wrote:I have been through these instructions at least 3 times now, starting with a fresh load of Raspbian each time. There are lots of errors and I don't even begin to know how to fix them.

I don't understand why one of the commands in the list is to uninstall NTP with apt-get , aren't we wanting NTP as part of the end picture?

I have passed all the GPS tests just wonder why in GPSMON the one field with NOTHING is PPS


Seems you got a little further than I did. I still can't get a /dev/pps0 - did you get that?

phipac
 
Posts: 2
Joined: Thu May 17, 2018 1:55 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by W8FG on Mon May 28, 2018 12:09 pm

I did manage to get a response with a sudo cat /dev/pps0 gave me response. Yet the field in GPSMON for the pps data never did get filled.

I have formatted my card and started fresh as I seem to be getting no where

W8FG
 
Posts: 4
Joined: Sat Sep 09, 2017 10:02 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by W8FG on Mon May 28, 2018 12:09 pm

I did manage to get a response with a sudo cat /dev/pps0 gave me response. Yet the field in GPSMON for the pps data never did get filled.

I have formatted my card and started fresh as I seem to be getting no where

W8FG
 
Posts: 4
Joined: Sat Sep 09, 2017 10:02 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by ramseyrt on Sat Feb 16, 2019 9:51 pm

Hello,

Is there a current, correct, and complete reference for configuring a GPS and PPS fed NTP server using the Ultimate GPS hat? I've been reading through all 17 pages of this post, in addition to several dozen other guides online. I just can't seem to get my configuration going using any single or hybrid set of procedures. I've completely rebuilt my OS at least six times attempting to accurately follow any one of the procedures online but none of them work all the way through.

Cordially,

Rob
kc8kpx

ramseyrt
 
Posts: 3
Joined: Sat Feb 16, 2019 9:45 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by LennyNero on Sun Feb 17, 2019 2:53 am

I found this one to be most helpful, but I don't recall 100% if there were some other little bits to take care of in regards to setting everything up as I did the setup on an early mornign after getting angry at a failed project. Rage-making as a way to calm my nerves lol. Be aware, doing the install disables the onboard bluetooth.

http://www.unixwiz.net/techtips/raspber ... -time.html

Additionally, I've installed ntpdate to be able to have a crontab set up to actually set the system clock.

Couple other things to note based on my memory of this setup and some things i've figured out along the way.
1. The GPS chipset in the hat available from adafruit is a mid-level position grade receiver (expect a best outcome of 5-10 microseconds with a 5-8 microsecond jitter) not a timing grade (2-50ns accuracy with ~2-10ns jitter) one. (I'm waiting for ublox to fully release the ZED-F9T which should be able to get <5ns accuracy with -/+5ns jitter and could be adapted onto a rival company's hat which uses the ublox ZED-F9P chipset currently) (Maybe we could get adafruit to produce a board for this chipset!)
2. The RPI you use for this project should be dedicated ONLY to NTP unless you somehow thermally isolate and insulate the hat from the rest of the RPI. The heat from the RPI will cause the GPS PPS signal to vary wildly upwards of 500 microseconds off. (Here is another place the timing grade GPS receivers do better due to better quality thermally compensated XOs). I wholeheartedly recommend enabling ssh access and only interfacing with it this way to keep load levels down on the RPI to further reduce heat in the unit.
3. The "GPS" NMEA string will be offset by a LOT and have tons of jitter due to the non-fixed NMEA string length on the adafruit GPS module. (so don't worry too much if you see it offset by over a half second). The offset can be partly adjusted for by changing the fudge factor in /etc/ntp.conf
FROM: fudge 127.127.28.0 refid GPS
TO: fudge 127.127.28.0 time1 +n.nnn refid GPS
Where n.nnn is the offset you're seeing in ntpq. (Note: you need to give the system a minimum of 4 hours to settle down after acquiring a GPS lock on the board.)

If you have any questions let me know. Maybe I'll reformat my rpi and start over again but actually document what I'm doing this time. lol.

-Daniel
-de W4DSA

LennyNero
 
Posts: 1
Joined: Sun Feb 17, 2019 2:16 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by ramseyrt on Sun Feb 17, 2019 4:34 pm

Hello Daniel,

I appreciate the suggestion on keeping the system cool. I hadn't considered the thermal impact to the oscillator's stability. I'm running on a Raspberry Pi 2 and plan to boot to CLI once I've gotten my configuration working and tested. My tolerance is within 1 second so a little variation shouldn't cause me much trouble.

I just came across your link earlier today. It does look like a great article and the author does a good job of describing why he's performing the steps he's describing. Like the author of that article stated, I've found GPS fed NTP setup to be mysterious. I used the article below to build a working configuration last night. Using its procedure, I was finally able to get, what looks like, a running configuration.

https://www.slsmk.com/how-to-setup-a-gps-pps-ntp-time-server-on-raspberry-pi/

### Begin of Rant ###

Based on all my research, there seems to be two approaches to getting the a GPS fed NTP system going. One approach disables gpsd, requiring the NTP daemon to source it's GPS and PPS information on it own, either from the GPS device directly or maybe from the kernel. The second approach enables gpsd, which provides the NTP daemon with GPS and PPS data via shared memory (which is the preferred method as it allows access the gps data with applications like cgps). Rare is the document that states upfront which method it's using.

The next stumbling block is the /etc/ntp.conf "server" and "fudge" syntax. This part is a total black box. The best document I've found so far provides some insight but is not clear in how the syntax is used (it could use a multitude of examples):

https://www.eecis.udel.edu/~mills/ntp/html/drivers/driver20.html

Almost all procedures use syntax including what looks like an IP address 127.127.XX.0. What's the significance of the third octet? Do any of the other octets mean anything? Most documents also reference "mode", "flag", and "refid" options but the presence of these and their use seems to vary widely. Oddly enough, I find forum posts where people are arguing the settings but nobody ever provides a citation to support their argument...

The last mystery is whether the booted kernel and installed version of NTP support PPS. You'd think that should be an easy thing to reveal using a "--version" argument to ntpd or having something declared in the output of a "uname -a" or "ntpq -crv", but there just doesn't seem to be any way to tell; or at least there's no document I've found that provides a method to check. So, there are tons of documents describing how to compile ntpd using any random assortment of flags after their "./configure" statement.

What a tough place to start from. Perhaps the worst part is that because no real knowledge is gained by working through any of these recipes, no understanding is gained by the user; making independent trouble-shooting impossible. There's a real need for all of this to be made clear.

I'm sure that there are a multitude of books and websites dedicated to NTP and that those sources likely include information regarding the relationship with and configuration of NTP using a GPS. Like so many other Linux/NTP/GPS enthusiasts, I don't have tremendous amounts of time to commit to a detailed study of NTP. Sure, a basic configuration using network time sources is easy but doing anything exotic, like sourcing from a GPS, is darn difficult. With the proliferation of network access (public Wi-Fi, cell networks, FIOS at home, etc.), I suppose there's little need for this level of synchronization outside of niche industrial or military applications. Maybe there's just so little need for the information that nobody's spent the time to boil it down for public consumption?

### End of Rant ###

How would I know if my configuration is really working? How would I know how well it's working? Based on the procedure linked above, I'm seeing the following after 12 hours:

Code: Select all | TOGGLE FULL SIZE
root@time:/home/pi# ntpq -crv -pn
associd=0 status=0115 leap_none, sync_pps, 1 event, clock_sync,
version="ntpd 4.2.8p10@1.3728-o Sat Mar 10 18:03:33 UTC 2018 (1)",
processor="armv7l", system="Linux/4.14.98-v7+", leap=00, stratum=1,
precision=-19, rootdelay=0.000, rootdisp=500.150, refid=PPS,
reftime=e0142ee4.642c6766  Sun, Feb 17 2019 13:05:08.391,
clock=e0142eef.629a5108  Sun, Feb 17 2019 13:05:19.385, peer=33730, tc=4,
mintc=3, offset=0.002635, frequency=-5.523, sys_jitter=0.001907,
clk_jitter=0.002, clk_wander=0.001
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
o127.127.22.0    .PPS.            0 l   11   16  377    0.000    0.003   0.002
*127.127.28.0    .GPS.            1 l   11   16  377    0.000  -166.28  38.599
+127.127.28.2    .SHM2.           0 l    9   16  377    0.000    0.003   0.002


Here are the lines from my /etc/ntp.conf (again, based on the link above):

Code: Select all | TOGGLE FULL SIZE
root@time:/home/pi# egrep -v '^$|^#' /etc/ntp.conf
driftfile /var/lib/ntp/ntp.drift
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict 127.0.0.1
restrict source notrap nomodify noquery
server 127.127.22.0 minpoll 4 maxpoll 4 true
fudge 127.127.22.0 flag3 1 refid PPS
server 127.127.28.0 minpoll 4 maxpoll 4 iburst prefer
fudge 127.127.28.0 flag1 1 time1 0.500 refid GPS stratum 1
server 127.127.28.2 minpoll 4 maxpoll 4
fudge 127.127.28.2 flag1 1 refid SHM2
tos mindist 0.5


According to this page, http://tech.kulish.com/2007/10/30/ntp-ntpq-output-explained/, my system has selected "GPS" as the time source and is using Pulse Per Second, "PPS". The date command shows an accurate date stamp but it generally does when I have a bad configuration too. The "Precision=-19" also generally displays when I have a bad configuration.

Thanks in advance,

Rob
kc8kpx
Attachments
IMG_1132.JPG
Raspberry Pi 2 w/Adafruit Ultimate GPS w/C4Labs case
IMG_1132.JPG (186.53 KiB) Viewed 53 times

ramseyrt
 
Posts: 3
Joined: Sat Feb 16, 2019 9:45 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by shawnerz on Sun Mar 03, 2019 4:37 am

You Sir, Mr Rob, are wonderful for posting this information!
I wholeheartedly agree with your rant.
My goal was to get the Ultimate GPS HAT to work on a Raspberry Pi Zero. It has taken the better part of 2 weekends. But with you posting your configuration, I was able to get it to work. It should not have been this hard.
If I get super-motivated, I may blow away this SD card and start again fresh.
To help others, below is my /boot/cmdline.txt /boot.config.txt and my ntp.conf
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi:~ $ cat /boot/cmdline.txt
dwc_otg.lpm_enable=0 enable_uart=1 root=PARTUUID=b42a8737-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait splash
pi@raspberrypi:~ $ cat /boot/config.txt
# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=off
#dtparam=i2s=on
dtparam=spi=off

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on
start_x=0
enable_uart=1

# Added by Shawn for GPS Support
dtoverlay=pps-gpio,gpiopin=4
pps-gpio

# Enable normal UART pins to work
#dtoverlay=pi3-miniuart-bt
init_uart_baud=38400
pi@raspberrypi:~ $ cat /etc/ntp.conf
# General Configuration


# Next 4 lines added  by Shawn
# Configuration to use local GPS board
server 127.127.22.0 minpoll 4 maxpoll 4 true
fudge 127.127.22.0  flag3 1 refid PPS
server 127.127.28.0 minpoll 4 maxpoll 4 iburst prefer
fudge 127.127.28.0 flag1 1 time1 0.500 refid GPS stratum 1
server 127.127.28.2 minpoll 4 maxpoll 4
fudge 127.127.28.2 flag1 1 refid SHM2
tos mindset 0.5

# Restrictions
restrict -4 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1

# Drift file

driftfile /etc/ntp/ntp.drift

# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
broadcast 192.168.1.255
pi@raspberrypi:~ $



There are probably things that could be deleted. But most of what I wanted works.
cgps -s is working. I'll provide a picture.
I'll also include a ntpq -crv -pn if I can post 2 pictures.

Perhaps others could help me. Another goal was to allow this Pi to be an NTP server to other computers on the network. I tried to get my Windows 7 PC to sync to the Pi, but the PC continually gave me an error. From my config files, can anyone see why the PC won't sync to the Pi?
Thanks, and thanks again Rob.
-Shawn
cgps -s.jpg
Output of cgps
cgps -s.jpg (113.68 KiB) Viewed 32 times

ntpq.jpg
ntpq pic
ntpq.jpg (87.61 KiB) Viewed 32 times

shawnerz
 
Posts: 5
Joined: Sat Jan 20, 2018 5:56 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by ramseyrt on Mon Mar 04, 2019 11:43 am

Hello Shawn,

I'm glad you liked my post : )

To get an NTP server going, you need to add the "restrict -4 default kod notrap nomodify nopeer noquery" line from this screen shot:

https://geek-university.com/wp-content/ ... strict.jpg

This allows NTP clients to access your NTP server is a very secure way. Once you've changed the line you'll need to restart the ntp daemon.

Cordially,

Rob

ramseyrt
 
Posts: 3
Joined: Sat Feb 16, 2019 9:45 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by shawnerz on Tue Mar 05, 2019 3:15 am

Hey there, Rob.
I think you meant the "restrict 192.168..." line. :)
I made the change for my home network (restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap).
At work, when forcing a Windows PC to sync the a local NTP server, I found I had to hit "Update Now" 3 times before Windows would accept the time. Here at home with the Pi, eve n after the magical 3rd time, Windows still reports an error. However, when I exit the window, Windows reports it successfully updated with the Pi.
If you look through my config file, you'll see that I have the Pi broadcast the time at .255. What I do not know is: did Windows actually get the time because I requested it, or did it catch the broadcast and update itself accordingly?
The other weird thing is, using Wireshark, when I hit 'Update now' in Windows, I don't see a NTP request go out. That fact makes me think Windows is catching the time from the broadcast. Who knows?
But thanks for your help. :)
-Shawn

shawnerz
 
Posts: 5
Joined: Sat Jan 20, 2018 5:56 pm

Please be positive and constructive with your questions and comments.