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 Tobi2707 on Mon Mar 23, 2015 2:51 pm

After setting the reset command still no fix or something:(
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 127.127.22.0    .PPS0.           1 l    -    8    0    0.000    0.000   0.000
 127.127.20.0    .GPS0.           1 l    -    8    0    0.000    0.000   0.000

Tobi2707
 
Posts: 87
Joined: Thu Mar 12, 2015 8:07 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Wed Mar 25, 2015 4:38 am

Any news so far?
Did you received your new Pi and the GPS HAT?:)

Tobi2707
 
Posts: 87
Joined: Thu Mar 12, 2015 8:07 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Wed Mar 25, 2015 10:56 am

Tobi2707 wrote:Any news so far?
Did you received your new Pi and the GPS HAT?:)


Yep, I got them both yesterday and I think I have a configuration that works. I let it run overnight and it seems to be stable so I'm going to write it up this morning.

gtj
 
Posts: 109
Joined: Wed Feb 04, 2015 9:11 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Wed Mar 25, 2015 11:17 am

Okay that's very nice:) I Hope this will fix the problem :)
So it World be nice of you can write something like a tutorial:)

Tobi2707
 
Posts: 87
Joined: Thu Mar 12, 2015 8:07 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Wed Mar 25, 2015 7:01 pm

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.
  • Build and Install NTP...
      Code: Select all | TOGGLE FULL SIZE
      $ cd /usr/src
      $ sudo mkdir ntp
      $ chown pi:pi ntp
      $ cd ntp
      $ wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p1.tar.gz
      $ tar -xzf ntp-4.2.8p1.tar.gz
      $ cd ntp-4.2.8p1
      $ ./configure --enable-all-clocks --enable-parse-clocks --disable-local-libopts --enable-step-slew --without-ntpsnmpd --enable-linuxcaps --prefix=/usr
      $ make -j5
      $ sudo apt-get remove ntp
      $ sudo apt-get install ntpdate
      $ sudo make install

    • Edit /etc/ntp.conf and adjust it as follows...
      Code: Select all | TOGGLE FULL SIZE
      # pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
      # pick a different set every time it starts up.  Please consider joining the
      # pool: <http://www.pool.ntp.org/join.html>
      server 0.debian.pool.ntp.org iburst
      #server 1.debian.pool.ntp.org iburst
      #server 2.debian.pool.ntp.org iburst
      #server 3.debian.pool.ntp.org iburst

      server 127.127.20.0 mode 84 minpoll 3 iburst prefer
      fudge 127.127.20.0 stratum 1 flag1 1 flag2 0 flag3 0 flag4 0 time1 0.0 time2 0.280 refid GPS0

      # Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
      # details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
      # might also be helpful.
    • Delete /etc/dhcp/dhclient-exit-hooks.d/ntp to prevent dhcp from overwriting the ntp config.
    • Create the file /etc/udev/rules.d/99-gps.rules with the following contents...
      Code: Select all | TOGGLE FULL SIZE
      KERNEL=="pps0",SYMLINK+="gpspps0"
      KERNEL=="ttyAMA0", SYMLINK+="gps0"
    • Run sudo udevadm trigger to create symlinks /dev/gps0 and /dev/gpspps0
  • Download and Install gps-tools
      Code: Select all | TOGGLE FULL SIZE
      $ cd /usr/src
      $ sudo mkdir gps-tools
      $ sudo chown pi:pi gps-tools
      $ cd gps-tools
      $ wget https://github.com/f5eng/mt3339-utils/archive/gps.zip
      $ unzip gps.zip
      $ cd mt3339-utils-gps
      $ sudo cp epoinfo epoloader eporetrieve gpsinit gpssend gpsstatus /usr/local/bin/
      $ sudo cp *.conf /etc/

  • Test GPS
    • Run sudo ppstest /dev/pps0. You should see timestamp every second. CTRL-C to exit.
    • Run gpsinit -s 115200 -f /etc/gpsinit_nav.conf /dev/ttyAMA0 to initialize the GPS unit for testing
    • Run gpsstatus /dev/ttyAMA0. Do you get a GPS or DGPS fix within 10 minutes? If not,
      Read the README at https://github.com/f5eng/mt3339-utils for instructions on how to initialize
      the GPS unit and why it's important.
  • Set up the GPS Unit for timekeeping
    • Run gpsinit -s 115200 -f /etc/gpsinit_time.conf /dev/ttyAMA0 to initialize the GPS unit
  • Start and test ntpd
      Code: Select all | TOGGLE FULL SIZE
      $ sudo update-rc.d ntp defaults
      $ sudo service ntp start
      $ sudo ntpq -pn

    • If the ppstest previously passed, you should eventually see...
      Code: Select all | TOGGLE FULL SIZE
           remote           refid      st t when poll reach   delay   offset  jitter
      ==============================================================================
      oGPS_NMEA(0)     .GPS0.           1 l    1    8  377    0.000    0.001   0.004
       xx.xx.xx.xx     PPS(1)           2 u    2    8  377    0.398   -0.072   0.212
    • The 'o' in the first column indicated that ntp is using the GPS for time.
  • Notes:
    • If you're Pi isn't network connected, you can set the system clock directly from the gps using the gpsinit command as long as ntpd isn't running.
      Code: Select all | TOGGLE FULL SIZE
      $ gpsinit -s 115200 -i set_system_clock /dev/ttyAMA0

      To do this at startup, edit /etc/rc.local and add the following lines at the bottom before the final 'exit 0'
      Code: Select all | TOGGLE FULL SIZE
      service ntp stop
      /usr/local/bin/gpsinit -s 115200 -i set_system_clock /dev/ttyAMA0
      service ntp start
Last edited by gtj on Thu Apr 09, 2015 3:28 pm, edited 4 times in total.

gtj
 
Posts: 109
Joined: Wed Feb 04, 2015 9:11 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Thu Mar 26, 2015 5:36 am

At first thank you for your How-To:)
So i tried to follow your tutorial and i got till the point ‚Test GPS‘, but first i have some notes in my case:

gtj wrote:Ok, Here's the process.

-Add dtoverlay=pps-gpio,gpiopin=18 to the end of /boot/config.txt
-Add pps-gpio to the end of /etc/modules

Sure that it's pin 18? You also have the Ultimate GPS HAT? Shouldn't it be pin 4? With pin 4 i get the new line every second running ppstest /dev/pps0 .

gtj wrote:Build and Install NTP...
    Code: Select all | TOGGLE FULL SIZE
    1 $ cd /usr/src
    2 $ mkdir ntp
    3 $ cd ntp
    4 $ wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p1.tar.gz
    5 $ tar -xzf ntp-4.2.8p1.tar.gz
    6 $ cd ntp-4.2.8p1.tar.gz
    7 $ ./configure --enable-all-clocks --enable-parse-clocks --disable-local-libopts --enable-step-slew --without-ntpsnmpd --enable-linuxcaps --prefix=/usr
    8 $ make -j5
    9 $ sudo apt-get remove ntp
    10 $ sudo make install



I'm logged in as pi so I have no permission to write in this folder. So I have to use 'sudo' in line 2, 4, 5, 7, 8 ?
And I think line 6 should be: '$ cd ntp-4.2.8p1' without the .tar.gz?
It should be said that you only use 'make -j5' if you're using a RPi 2, with and RPI B+ it's just 'make'.
So the final folder for the make command should be: /usr/src/ntp/ntp-4.2.8p1 ?

gtj wrote:
  • Edit /etc/ntp.conf and adjust it as follows...
    Code: Select all | TOGGLE FULL SIZE
    # pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
    # pick a different set every time it starts up.  Please consider joining the
    # pool: <http://www.pool.ntp.org/join.html>
    server 0.debian.pool.ntp.org iburst noselect
    #server 1.debian.pool.ntp.org iburst
    #server 2.debian.pool.ntp.org iburst
    #server 3.debian.pool.ntp.org iburst

    server 127.127.20.0 mode 84 minpoll 3 iburst prefer
    fudge 127.127.20.0 stratum 1 flag1 1 flag2 0 flag3 0 flag4 0 time1 0.0 time2 0.280 refid GPS0

    # Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
    # details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
    # might also be helpful.


  • Are you sure that mode 84 is right? And if so, whats the difference to 88?


    gtj wrote:Run sudo udevadm trigger to create symlinks /dev/gps0 and /dev/gpspps0

    Is it right that i don’t get an response output here?

    gtj wrote:Test GPS
    1. Run sudo ppstest /dev/pps0. You should see timestamp every second. CTRL-C to exit.
    2. Run gpsinit -s 115200 -f /etc/gpsinit_nav.conf /dev/ttyAMA0 to initialize the GPS unit for testing
    3. Run gpsstatus /dev/ttyAMA0. Do you get a GPS or DGPS fix within 10 minutes? If not,
    Read the README at https://github.com/f5eng/mt3339-utils for instructions on how to initialize
    the GPS unit and why it's important.


    Point 1 does works, but i got an error with point 2:
    Code: Select all | TOGGLE FULL SIZE
    pi@raspberrypi ~ $ gpsinit -s 115200 -f /etc/gpsinit_nav.conf /dev/ttyAMA0
    Making sure the unit is in NMEA mode
    Making sure the speeds match
    Traceback (most recent call last):
      File "/usr/local/bin/gpsinit", line 293, in <module>
        sys.exit(main() or 0)
      File "/usr/local/bin/gpsinit", line 263, in main
        fg = get_known_state(args.output_device, args.speed, None, False)
      File "/usr/local/bin/gpsinit", line 227, in get_known_state
        resp = send_and_wait(fg, "PMTK000", 5)
      File "/usr/local/bin/gpsinit", line 97, in send_and_wait
        thread = rx_loop_thread(fg)
    TypeError: __init__() takes exactly 3 arguments (2 given)



    This error als appears when im running the factory reset command, so i can't set it back to factory state.

    So i can’t go on, but it is almost done:)

    Tobi2707
     
    Posts: 87
    Joined: Thu Mar 12, 2015 8:07 am

    Re: Raspberry Pi GPS Stratum 1 NTP Server

    by gtj on Thu Mar 26, 2015 11:25 am

    Tobi2707 wrote:At first thank you for your How-To:)
    So i tried to follow your tutorial and i got till the point ‚Test GPS‘, but first i have some notes in my case:
    Sure that it's pin 18? You also have the Ultimate GPS HAT? Shouldn't it be pin 4? With pin 4 i get the new line every second running ppstest /dev/pps0 .

    Yes. Pin 4 on the hat is actually wired to GPIO 18 on the Pi.

    Tobi2707 wrote:I'm logged in as pi so I have no permission to write in this folder. So I have to use 'sudo' in line 2, 4, 5, 7, 8 ?
    And I think line 6 should be: '$ cd ntp-4.2.8p1' without the .tar.gz?
    It should be said that you only use 'make -j5' if you're using a RPi 2, with and RPI B+ it's just 'make'.
    So the final folder for the make command should be: /usr/src/ntp/ntp-4.2.8p1 ?

    Ah, I forgot about that. Rather than doing 'sudo' for each line, you can do the following...
    Code: Select all | TOGGLE FULL SIZE
    $ cd /usr/src
    $ sudo mkdir ntp
    $ sudo chown pi:pi ntp
    $ cd ntp

    That'll make you the owner of the directory. You'll still need to use sudo for the 'make install'.
    Correct on the other points.

    Tobi2707 wrote:Are you sure that mode 84 is right? And if so, whats the difference to 88?

    Yes. 80 is the mode for 115200 baud. Adding 4 causes ntp to use the GPGLL sentence (the first one output). Adding 8 says to use GPZDA. Turns out GPGLL is better aligned to the PPS pulse.

    Tobi2707 wrote:Is it right that i don’t get an response output here?

    Correct. The links should have been created though.

    Tobi2707 wrote:Point 1 does works, but i got an error with point 2:
    Code: Select all | TOGGLE FULL SIZE
    pi@raspberrypi ~ $ gpsinit -s 115200 -f /etc/gpsinit_nav.conf /dev/ttyAMA0
    Making sure the unit is in NMEA mode
    Making sure the speeds match
    Traceback (most recent call last):
      File "/usr/local/bin/gpsinit", line 293, in <module>
        sys.exit(main() or 0)
      File "/usr/local/bin/gpsinit", line 263, in main
        fg = get_known_state(args.output_device, args.speed, None, False)
      File "/usr/local/bin/gpsinit", line 227, in get_known_state
        resp = send_and_wait(fg, "PMTK000", 5)
      File "/usr/local/bin/gpsinit", line 97, in send_and_wait
        thread = rx_loop_thread(fg)
    TypeError: __init__() takes exactly 3 arguments (2 given)


    This error als appears when im running the factory reset command, so i can't set it back to factory state.

    So i can’t go on, but it is almost done:)


    Oops. That's a bug. I can correct that pretty quickly. Give me about 30 minutes.

    gtj
     
    Posts: 109
    Joined: Wed Feb 04, 2015 9:11 pm

    Re: Raspberry Pi GPS Stratum 1 NTP Server

    by gtj on Thu Mar 26, 2015 11:44 am

    Ok, I fixed the bug in gpsinit. Re-download https://github.com/f5eng/mt3339-utils/archive/gps.zip and install it and you should be good to go.

    gtj
     
    Posts: 109
    Joined: Wed Feb 04, 2015 9:11 pm

    Re: Raspberry Pi GPS Stratum 1 NTP Server

    by Tobi2707 on Thu Mar 26, 2015 11:54 am

    Thanks:)
    Something to delete before?
    And the RPi was shut down, does this matter?

    Tobi2707
     
    Posts: 87
    Joined: Thu Mar 12, 2015 8:07 am

    Re: Raspberry Pi GPS Stratum 1 NTP Server

    by gtj on Thu Mar 26, 2015 12:05 pm

    Oh, you were absolutely correct on the pin being 4. I was confused. So it should be "dtoverlay=pps-gpio,gpiopin=4".

    gtj
     
    Posts: 109
    Joined: Wed Feb 04, 2015 9:11 pm

    Re: Raspberry Pi GPS Stratum 1 NTP Server

    by gtj on Thu Mar 26, 2015 12:07 pm

    Tobi2707 wrote:Thanks:)
    Something to delete before?
    And the RPi was shut down, does this matter?


    Nothing to delete, just recopy the files.
    No issue with the Pi shutting down.

    gtj
     
    Posts: 109
    Joined: Wed Feb 04, 2015 9:11 pm

    Re: Raspberry Pi GPS Stratum 1 NTP Server

    by Tobi2707 on Thu Mar 26, 2015 12:11 pm

    Now i got this error:
    Code: Select all | TOGGLE FULL SIZE
    pi@raspberrypi ~ $ gpsinit -s 115200 -f /etc/gpsinit_nav.conf /dev/ttyAMA0
    Making sure the unit is in NMEA mode
    Making sure the speeds match
    The GPS speed and the port speed couldn't be synchronized.
    Retrying
    Making sure the speeds match
    The GPS speed and the port speed couldn't be synchronized.

    Tobi2707
     
    Posts: 87
    Joined: Thu Mar 12, 2015 8:07 am

    Re: Raspberry Pi GPS Stratum 1 NTP Server

    by gtj on Thu Mar 26, 2015 12:15 pm

    Just try it a few times.

    gtj
     
    Posts: 109
    Joined: Wed Feb 04, 2015 9:11 pm

    Re: Raspberry Pi GPS Stratum 1 NTP Server

    by Tobi2707 on Thu Mar 26, 2015 12:19 pm

    How often?:P
    i tried it 10 times and still same error :(

    Maybe something went wrong during recopy?

    Tobi2707
     
    Posts: 87
    Joined: Thu Mar 12, 2015 8:07 am

    Re: Raspberry Pi GPS Stratum 1 NTP Server

    by gtj on Thu Mar 26, 2015 12:23 pm

    You're sure ntpd isn't running? Can you do the 'gpsstatus /dev/ttyAMA0'?

    gtj
     
    Posts: 109
    Joined: Wed Feb 04, 2015 9:11 pm

    Please be positive and constructive with your questions and comments.