The new and improved Saskatoon Techworks wiki, powered by DokuWiki.

Stratum 1 NTP Setup on Raspberry Pi

By: Bun-Bun & guppy
  • This guides uses Uputronics Raspberry Pi+ GPS Expansion Board and a rpi3 or newer
  • Setup rpi with latest Raspbian, enable ssh, etc…
  • apt-get install vim
  • raspi-config #disable linux from trying to access console getty
    • 5 Interfacing Options
    • P6 Serial → Login Shell (no) → Enable Hardware (yes)
  • vi /boot/config.txt
    • Add the following to the bottom
    • enable_uart=1
      dtoverlay=pi3-disable-bt #same with rpi4
      #dtoverlay=pi3-miniuart-bt #if you want software BT
      dtoverlay=pps-gpio,gpiopin=18
      init_uart_baud=9600
  • systemctl disable hciuart #prevents warnings in logfiles
  • systemctl mask serial-getty@ttyAMA0.service #disables console getty so we can use uart for pps
  • apt-get install pps-tools ntp dnsutils
  • reboot
  • dmesg | grep pps
    • Look for the following
    • [ 2.443494] pps_core: LinuxPPS API ver. 1 registered
      [ 2.446699] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
      [ 2.471796] pps pps0: new PPS source pps.-1
      [ 2.471886] pps pps0: Registered IRQ 498 as PPS source
      [ 6.965166] pps_ldisc: PPS line discipline registered
      [ 6.966569] pps pps1: new PPS source ttyAMA0
      [ 6.966664] pps pps1: source "/dev/ttyAMA0" added
  • Check receiving stuff from gps module
    • ppstest /dev/pps0 #pps on gpio
    • cat /dev/ttyAMA0 #serial from gps module
  • vi /etc/ntp.conf
    • Change servers as appropriate, stuff at the bottom is the gpsd and pps link
    • Can have no servers and only use gps/pps as source, or have more than 1 other. Two sources (yourself and some other server) is bad.
    • # Enable this if you want statistics to be logged.
      #statsdir /var/log/ntpstats/
      
      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
      
      
      # You do need to talk to an NTP server or two (or three).
      #server ntp.your-provider.example
      
      #Can have no servers and only use gps/pps as source, or have more than 1 other. Two sources (yourself and some other server) is bad.
      #server tock.usask.ca
      #server ntp2.torix.ca
      #server ntp.zaf.ca
      
      # 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.
      #
      # Note that "restrict" applies to both servers and clients, so a configuration
      # that might be intended to block requests from certain clients could also end
      # up blocking replies from your own upstream servers.
      
      # By default, exchange time with everybody, but don't allow configuration.
      restrict -4 default kod notrap nomodify nopeer noquery
      restrict -6 default kod notrap nomodify nopeer noquery
      
      # Local users may interrogate the ntp server more closely.
      restrict 127.0.0.1
      restrict ::1
      
      # Needed for adding pool entries
      restrict source notrap nomodify noquery
      
      # Clients from this (example!) subnet have unlimited access, but only if
      # cryptographically authenticated.
      #restrict 192.168.123.0 mask 255.255.255.0 notrust
      
      
      # If you want to provide time to your local subnet, change the next line.
      # (Again, the address is an example only.)
      #broadcast 192.168.123.255
      
      # If you want to listen to time broadcasts on your local subnet, de-comment the
      # next lines.  Please do this only if you trust everybody on the network!
      #disable auth
      #broadcastclient
      #
      server 127.127.22.0 minpoll 4 maxpoll 4
      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 time1 +0.105 flag1 1 refid GPSD stratum 1
      tos mindist 0.015 #something about accepting a certain amount of jitter from serial sources
  • apt-get install gpsd gpsd-clients
  • systemctl enable gpsd
  • vi /etc/default/gpsd
    • Edit devices and options as shown below
    • # Default settings for the gpsd init script and the hotplug wrapper.
      
      # Start the gpsd daemon automatically at boot time
      START_DAEMON="true"
      
      # Use USB hotplugging to add new USB devices automatically to the daemon
      USBAUTO="true"
      
      # Devices gpsd should collect to at boot time.
      # They need to be read/writeable, either by user gpsd or the group dialout.
      DEVICES="/dev/ttyAMA0 /dev/pps0"
      
      # Other options you want to pass to gpsd
      GPSD_OPTIONS="-n"
  • gpsControl files and install.sh #for stationary mode (Credit to guppy for creating and Bun-Bun for correcting)
  • Disable NTP from dhcp
    • echo "" > /etc/dhcp/dhclient-exit-hooks.d/ntp
      echo "" > /var/lib/ntp/ntp.conf.dhcp
      chattr +i /etc/dhcp/dhclient-exit-hooks.d/ntp
      chattr +i /var/lib/ntp/ntp.conf.dhcp
  • reboot
  • gpsmon #also cgps -s
  • ntpq -p #wait a bit so everything can get going
  • More reading

Optimizations

  • Add nohz=off to the end of the line in /etc/cmdline.txt
  • configure system to run cpu full speed
    • apt -y install cpufrequtils
      echo 'GOVERNOR="performance"' > /etc/default/cpufrequtils
      systemctl restart cpufrequtils
  • Remove useless stuff
    • apt -y purge bluez triggerhappy wpasupplicant alsa-utils
      systemctl stop avahi-daemon
      systemctl disable avahi-daemon
      apt -y autoremove
      apt clean
Print/export
QR Code
QR Code stratum1ntp (generated for current page)