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 Rickinfl on Thu Jul 07, 2016 3:53 pm

I can verify that jforhan post does work with Raspberry Pi 3's.

Rickinfl
 
Posts: 4
Joined: Mon Jul 04, 2016 2:03 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by tom_w on Tue Aug 16, 2016 5:12 pm

Well after a long hiatus I am back at this. I'm using a RPi2 and the latest Raspbian.

I'm going through the steps and I have reached the following problem. To summarize, when I run "sudo udevadm trigger", /dev/gps0 is not created.

Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi:/etc/dhcp/dhclient-exit-hooks.d $ sudo udevadm trigger
pi@raspberrypi:/etc/dhcp/dhclient-exit-hooks.d $ cd /dev/
pi@raspberrypi:/dev $ ls
autofs           fuse     loop5             network_throughput  ram15   snd     tty16  tty28  tty4   tty51  tty63      vcs1   vcsa6
block            gpiomem  loop6             null                ram2    stderr  tty17  tty29  tty40  tty52  tty7       vcs2   vcsa7
btrfs-control    gpspps0  loop7             ppp                 ram3    stdin   tty18  tty3   tty41  tty53  tty8       vcs3   vcsm
bus              hwrng    loop-control      pps0                ram4    stdout  tty19  tty30  tty42  tty54  tty9       vcs4   vhci
cachefiles       initctl  mapper            ptmx                ram5    tty     tty2   tty31  tty43  tty55  ttyprintk  vcs5   watchdog
char             input    mem               pts                 ram6    tty0    tty20  tty32  tty44  tty56  uhid       vcs6   watchdog0
console          kmsg     memory_bandwidth  ram0                ram7    tty1    tty21  tty33  tty45  tty57  uinput     vcs7   xconsole
cpu_dma_latency  log      mmcblk0           ram1                ram8    tty10   tty22  tty34  tty46  tty58  urandom    vcsa   zero
cuse             loop0    mmcblk0p1         ram10               ram9    tty11   tty23  tty35  tty47  tty59  vc-cma     vcsa1
disk             loop1    mmcblk0p2         ram11               random  tty12   tty24  tty36  tty48  tty6   vchiq      vcsa2
fb0              loop2    mqueue            ram12               raw     tty13   tty25  tty37  tty49  tty60  vcio       vcsa3
fd               loop3    net               ram13               rfkill  tty14   tty26  tty38  tty5   tty61  vc-mem     vcsa4
full             loop4    network_latency   ram14               shm     tty15   tty27  tty39  tty50  tty62  vcs        vcsa5


Moving on from this issue I run into the following when I try to initialize gps for testing.
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi:/usr/src/gps-tools/mt3339-utils-gps $ gpsinit -s 115200 -f /etc/gpsinit_nav.conf /dev/ttyAMA0
Traceback (most recent call last):
  File "/usr/local/bin/gpsinit", line 343, in <module>
    sys.exit(main() or 0)
  File "/usr/local/bin/gpsinit", line 310, in main
    fg = get_known_state(args.output_device, args.speed, None, False)
  File "/usr/local/bin/gpsinit", line 241, in get_known_state
    fg = serial.Serial(port=device, timeout=5, baudrate=speed)
  File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 261, in __init__
    self.open()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 278, in open
    raise SerialException("could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: could not open port /dev/ttyAMA0: [Errno 2] No such file or directory: '/dev/ttyAMA0'

tom_w
 
Posts: 32
Joined: Mon Mar 03, 2014 11:32 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by jforhan on Sat Aug 20, 2016 10:32 am

Tom,

Sorry you are having issues. Page 5 of this thread, 5th post down is where you need to start checking. It details the steps.

My guess is you have not disabled the login shell from the "/boot/cmdline.txt" file.
I see no "ttyAMA0" nor "serial0" in your listing for the /dev directory.

Your cmdline.txt may look like this:
Code: Select all | TOGGLE FULL SIZE
dwc_otg.lpm_enable=0 [u]console=ttyAMA0,115200[/u] root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait


You need to remove the reference to "console".
Code: Select all | TOGGLE FULL SIZE
dwc_otg.lpm_enable=0 root=/dev/mmcblk0p7 initrd=-1 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait


After removing the reference you need to reboot. Would be good to double check your UDEV rules file to make sure there are no typos, etc. first.

If the above doesn't work then;
Post the output of your files "/etc/udev/rules.d/99-gps.rules","/boot/cmdline.txt" & "/boot/config.txt"

Later,
Jeff

jforhan
 
Posts: 12
Joined: Fri Apr 29, 2016 8:18 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by jbouse on Sat Aug 20, 2016 11:05 pm

Thanks in great part to many of the posts in this long thread I have my Raspberry Pi 2 running with my Ultimate GPS HAT successfully... I have made some deviations from the instructions that I found on here and did some of the configuration differently but that likely comes more from my 20+ years of Linux SysAdmin work and 15+ years of working with Debian. I am working to put all of my steps together on my website as well as including the ntp .deb packages that I built for Raspbian 8.0 (Jessie) which will have the .dsc and .changes files signed by my Debian Developer key.

Key differences of note, first I never used the gpsinit scipt I saw being mentioned. Instead I simply set init_uart_baud=38400 in my /boot/config.txt and then set my entries in /etc/ntp.conf to be:
Code: Select all | TOGGLE FULL SIZE
server 127.127.20.0 mode 48 minpoll 3 iburst prefer
fudge 127.127.20.0 refid GPS flag1 1 flag4 1 time2 0.280

I did try setting the uart baud rate at very settings until I found the highest that everything still worked. Originally setting it to 9600 seemed to produce somewhat unreliable results and setting it to 115200 I didn't get any output at all, so I settled for 38400 which is the highest I found I got reliable responses from.
With flag1 set to 1 I found that I did not need to add the 127.127.22.0 (ATOM_PPS) server and when I did I started getting the dreaded issue of both GPS and PPS getting X'd out even when I set flag1 back to it's default of 0. I believe that was because they were both competing for use of /dev/pps0 & /dev/gpspps0.

My current 'ntpq -p' output is:
Code: Select all | TOGGLE FULL SIZE
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+fairy.mattnordh 200.98.196.212   2 u   49   64  377   39.710   -7.961   1.834
*navobs1.gatech. .GPS.            1 u   52   64  377   28.841   -4.318   8.302
oGPS_NMEA(0)     .GPS.            0 l    -    8  377    0.000    0.001   0.001

Here's a sample of my clockstats:
Code: Select all | TOGGLE FULL SIZE
57621 9791.468 127.127.20.0 $GPGGA,024311.000,____.____,N,_____.____,W,2,09,1.05,283.5,M,-30.6,M,0000,0000*__
57621 9799.468 127.127.20.0 $GPGGA,024318.000,____.____,N,_____.____,W,2,09,1.05,283.5,M,-30.6,M,0000,0000*__
57621 9807.468 127.127.20.0 $GPGGA,024327.000,____.____,N,_____.____,W,2,09,1.05,283.5,M,-30.6,M,0000,0000*__
57621 9815.468 127.127.20.0 $GPGGA,024335.000,____.____,N,_____.____,W,2,09,1.05,283.5,M,-30.6,M,0000,0000*__
57621 9823.468 127.127.20.0 $GPGGA,024342.000,____.____,N,_____.____,W,2,09,1.05,283.5,M,-30.6,M,0000,0000*__
57621 9831.468 127.127.20.0 $GPGGA,024350.000,____.____,N,_____.____,W,2,09,1.05,283.5,M,-30.6,M,0000,0000*__
57621 9839.468 127.127.20.0 $GPGGA,024358.000,____.____,N,_____.____,W,2,09,1.05,283.6,M,-30.6,M,0000,0000*__
57621 9847.468 127.127.20.0 $GPGGA,024406.000,____.____,N,_____.____,W,2,10,0.95,283.6,M,-30.6,M,0000,0000*__
57621 9855.468 127.127.20.0 $GPGGA,024414.000,____.____,N,_____.____,W,2,10,0.95,283.6,M,-30.6,M,0000,0000*__
57621 9863.468 127.127.20.0 $GPGGA,024422.000,____.____,N,_____.____,W,2,10,0.95,283.6,M,-30.6,M,0000,0000*__

and loopstats output:
Code: Select all | TOGGLE FULL SIZE
57621 9839.468 0.000001086 -2.174 0.000001037 0.000422 3
57621 9847.468 0.000001538 -2.173 0.000001027 0.000475 3
57621 9855.468 -0.000000487 -2.174 0.000001199 0.000453 3
57621 9863.468 -0.000000829 -2.174 0.000001171 0.000446 3
57621 9871.468 0.000001251 -2.173 0.000001320 0.000470 3
57621 9879.468 0.000001846 -2.173 0.000001280 0.000543 3
57621 9887.468 0.000000450 -2.172 0.000001295 0.000513 3
57621 9895.468 -0.000000875 -2.173 0.000001299 0.000503 3
57621 9903.468 0.000000057 -2.173 0.000001261 0.000471 3
57621 9911.468 -0.000000956 -2.173 0.000001233 0.000471 3

I'd love to be able to get some of the stats being graphed to see how it goes long-term... Just eyeballing the output I've seen very little variance in either stats files.
The unit has been bounce tested several times so as to ensure that everything comes back up properly.
While it was working fairly reliably with only the internal antenna while I waited for an SMA coupling adapter to be able to hook up my active external antenna, it has been nothing but solid since attaching it.

jbouse
 
Posts: 2
Joined: Sat Aug 20, 2016 10:26 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by tom_w on Mon Aug 22, 2016 8:37 am

jforhan wrote:Tom,

Sorry you are having issues.


Thanks for the reply, Jeff. When I have time to face this head on, I will come back to this.

However, I am trying to complete this project quickly. To avoid most issues, I purchased a B+, which allowed me to run Wheezy without issue. I then followed the following tutorial:

http://www.reeve.com/Documents/Articles%20Papers/Reeve_GpsNtp-Pi_Setup.pdf

I found this document to be a fine example of technical writing. I also had no issues with the procedure. I'm currently seeing about 1-3ms offset:

Code: Select all | TOGGLE FULL SIZE
pi@GpsNtp-Pi ~ $ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*SHM(0)          .GPSD.           0 l    4   16  377    0.000   13.205   5.899
oPPS(0)          .KPPS.           0 l    5   16  377    0.000    0.001   0.002


The issue that I face now, is that I used a mac, and the author used a windows machine. As a result I am not certain how to set my mac to the time of the RPi. The author discussed an NTP client program, but I think I should be able to do this through the command line.

Any suggestions?

Also, like jbouse, I am interested in plotting my offset and jitter data.

Finally, what enclosures are people using for their RPi and the Adafruit Ultimate GPS Hat? Modmypi has a case, but they claim it only works with the hab supplies GPS hat.
Case:
https://www.modmypi.com/raspberry-pi/cases/modmypi-single-colour/gps-case-black/?search=gps%20hat
Hab Supplies GPS Hat:
https://www.modmypi.com/raspberry-pi/breakout-boards/hab-supplies/raspberry-pi-gps-hat/?search=gps%20hat

tom_w
 
Posts: 32
Joined: Mon Mar 03, 2014 11:32 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by jforhan on Wed Aug 24, 2016 11:18 am

Tom,

I never tried GPSd. But I have not many troubles getting RPi 2 and 3 to work. I was able to work through everything.

As for the MAC, you can specify a server manually in system preferences. In system preferences, click on time and date. Then enter the IP/hostname of your Pi.

I have a CentOS server using GPS receiver. On my MAC I had this:

Code: Select all | TOGGLE FULL SIZE
 jforhan$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 rtp10-a9-rbb-nt .GPS.            1 u  196  256   77   48.764  -1725.2   2.753


I then added my server hostname as specified above and it shows up:
Code: Select all | TOGGLE FULL SIZE
 jforhan$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 bxb-jforhan-nit .PPS.            1 u   33   64    1    2.924   19.797   0.001
 rtp10-a9-rbb-nt .GPS.            1 u   32   64    1  255.594    4.064   0.001


For cases I use the CY Case for Raspberry Pi. Search the Interwebs and you will find it.

Later,
Jeff

jforhan
 
Posts: 12
Joined: Fri Apr 29, 2016 8:18 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Mpegger on Thu Aug 25, 2016 7:50 pm

I'm new to the Raspberry Pi (and Linux) and just came across this thread. Very informative, though I haven't read through every post yet. I have, however, read through many guides and I see that most of the guides use a packaged GPS module on a board to use on the R.Pi. I'm curious if anyone has used, or if it's even possible to use, the bare GPS chip offered on Adafruit, https://www.adafruit.com/products/790? From what I can see in the photo of the Ultimate GPS Breakout, the board just has the traces all routed to one edge for easy soldering from the chip, as well as a Voltage regulator circuit (not sure if that's what it is), and a external antenna jack circuit. It doesn't appear to me that the Ultimate version is needed, if the GPS chip itself can provide the same funtionality for $10 less (I will not require a external antenna for my setup and the R.Pi can output 3.3V). Is there any reason why I couldn't just use the bare chip with the R.Pi for a NTP server?

Mpegger
 
Posts: 2
Joined: Thu Aug 25, 2016 7:34 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by jforhan on Thu Aug 25, 2016 8:53 pm

Hey Mpegger! Welcome...

I have built a GPS unit with the Ultimate GPS. (I have also used the HAT). However I did not use the board directly to the RPi. I used a very small project box, added a TTL<->RS-232 level shifter and a micro USB input for power. I connected the PPS directly to PIN#1 on the Female DB-9 of the shifter and use it with a Linux box. This would work with the RPi with a USB-to-serial cable. (It has been my experience however that the USB-to-serial adapters do not seem to like the PPS on pin 1). There is no reason you couldn't wire up the Tx/Rx directly to the RPi TTL level UART as you do the HAT. It would just require one to mount it somewhere in a case that has enough room or use a bread board.

HTH

Later,
Jeff

jforhan
 
Posts: 12
Joined: Fri Apr 29, 2016 8:18 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Mpegger on Fri Aug 26, 2016 7:51 am

The case would be no problem. I plan on using the GPS module in a waterproof case outdoors with the R.Pi indoor, since it will be attached via wires anyway directly to the GPIO pins. I just want to be sure that the naked module can be used instead of the Ultimate module. I'm trying to keep the cost as low as possible on this build and it would be a big waste to buy the naked module, only to find that the Ultimate is in fact needed.

Mpegger
 
Posts: 2
Joined: Thu Aug 25, 2016 7:34 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by jbouse on Sun Aug 28, 2016 3:09 am

If it helps anyone else running Raspbian 8, or anyone that would like to help test the package build...
I've rebuilt to include support for ATOM_PPS as well as upgrade from the default 4.2.6p5 version in Jessie to the newer 4.2.8p8 version found in Stretch.

You can create the file /etc/apt/sources.list.d/jbouse-debian.list with the following content:
Code: Select all | TOGGLE FULL SIZE
deb https://jbouse-debian.s3.amazonaws.com/debian/ jessie main


Next you'll need to add my Debian Developer GPG key to the apt keyring using the following:
Code: Select all | TOGGLE FULL SIZE
apt-key adv --keyserver keyring.debian.org --recv-key 0xFFCE1C9A4FADF197


If you don't want to pull it down from the Debian keyring server you can install from the debian-keyring package using:
Code: Select all | TOGGLE FULL SIZE
gpg --keyring /usr/share/keyrings/debian-keyring.gpg --armor --export 0xFFCE1C9A4FADF197 |apt-key add -


If the above commands are not being ran as root, you'll obviously need to run apt-key through sudo.

For those that would like to validate further... Here are my GPG key details:
Code: Select all | TOGGLE FULL SIZE
pub   4096R/0xFFCE1C9A4FADF197 2011-12-23 [expires: 2019-07-31]
      Key fingerprint = 09C5 AB71 078F 4ACD 235B  28E5 FFCE 1C9A 4FAD F197
uid                 [ultimate] Jeremy T. Bouse (Debian Developer) <jbouse@debian.org>
sub   3072R/0x64B95A8D6E20BD24 2011-12-24 [expires: 2018-04-10]
sub   3072R/0x8E19025A91608CAD 2011-12-24 [expires: 2018-04-10]
sub   3072R/0x6A9956B4E8356ECC 2011-12-24

jbouse
 
Posts: 2
Joined: Sat Aug 20, 2016 10:26 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by kagestodder on Sun Oct 30, 2016 4:31 pm

I have tried the guide on page 5 twice now, but run into the same issue both times.

When i get to the part "Test GPS" and write

gpsinit -s 115200 -f /etc/gpsinit_nav.conf /dev/ttyAMA0


I get the following response:

Traceback (most recent call last):
File "/usr/local/bin/gpsinit", line 16 in <module>
import serial
ImportError: No module named serial


I am running a clean Raspbian Jessie lite, with the only code run is the code in this thread.

If anyone knows whats wrong i would be grateful, thanks!

kagestodder
 
Posts: 2
Joined: Sun Oct 30, 2016 4:27 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by jforhan on Sun Oct 30, 2016 5:55 pm

You need to install python-serial. Lite doesn't include all the modules you need. "sudo apt-get install python-serial". It should pick up any other requirements you need as well.

Later,
Jeff

jforhan
 
Posts: 12
Joined: Fri Apr 29, 2016 8:18 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by kagestodder on Mon Oct 31, 2016 5:41 am

Thanks for your reply!

Going back and forth trying to solve different stuff i suddenly notice the gps isn't working correct anymore. When initializing the gps i get the following error:

Making sure the unit is in NMEA mode
Making sure speeds match
The GPS speed and the port speed couldn't be synchronized.
Retrying
Making sure speeds match
The GPS speed and the port speed couldn't be synchronized.


I had to enable UART in the boot config file since i wouldn't get ttyAMA0 in my /dev/ folder....

Otherwise everything works. I am able to write the ntp command to show delay and everything. Though the GPS0 has - "when" and "reach" is 0.


---------------

Tryed to start over again. I see some repetition. I had to enable UART to get dev/ttyAMA0.

After enabling UART i try to start nt. service by:

sudo service ntp start


and get

Job for ntp.service failed. See 'systemctl status ntp.service and 'journalct1 -xn' for details


Here is the output for ls -l /etc/init.d/ntp

-rqr-xr 1 root root 1814 dec 26 2009 /etc/init.d/npt


Not really sure how to post cat /etc/init.d/ntp since its huge and am not able to directly copy/paste it.

In my previous version i tried to install ntp tools again as suggested by an internet post which worked. Not sure if this will affect other stuff on the Pi and undue something that i did previously.

BR

kagestodder
 
Posts: 2
Joined: Sun Oct 30, 2016 4:27 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by eggert_ehmke on Wed Sep 06, 2017 7:08 am

I can't get the sudo ppstest /dev/pps0 step to run. I have the Raspberry 3B and the Dragino LORA/GPS HAT. I have soldered the PPS pin to GPIO18 (Pin 12) and set dtoverlay=pps-gpio,gpiopin=12 into /boot/config.txt. Still I get
Code: Select all | TOGGLE FULL SIZE
$ sudo ppstest /dev/pps0
trying PPS source "/dev/pps0"
found PPS source "/dev/pps0"
ok, found 1 source(s), now start fetching data...
time_pps_fetch() error -1 (Connection timed out)
time_pps_fetch() error -1 (Connection timed out)

even when the blue GPS FIX led is blinking and I have valid position and time information. What am I missing?
eggert_ehmke
 
Posts: 5
Joined: Thu May 15, 2014 5:02 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by eggert_ehmke on Wed Sep 06, 2017 12:06 pm

eggert_ehmke wrote:I can't get the sudo ppstest /dev/pps0 step to run. I have the Raspberry 3B and the Dragino LORA/GPS HAT. I have soldered the PPS pin to GPIO18 (Pin 12) and set dtoverlay=pps-gpio,gpiopin=12 into /boot/config.txt. Still I get
Code: Select all | TOGGLE FULL SIZE
$ sudo ppstest /dev/pps0
trying PPS source "/dev/pps0"
found PPS source "/dev/pps0"
ok, found 1 source(s), now start fetching data...
time_pps_fetch() error -1 (Connection timed out)
time_pps_fetch() error -1 (Connection timed out)

even when the blue GPS FIX led is blinking and I have valid position and time information. What am I missing?


Even when the parameter is called gpiopin, the gpio number must be used. With gpiopin=18 it works.
eggert_ehmke
 
Posts: 5
Joined: Thu May 15, 2014 5:02 pm

Please be positive and constructive with your questions and comments.