This is an old revision of the document!


Stratum 1 NTP Setup on Raspberry Pi

  • 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)
  • 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
    • # 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
      
      #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 ignoring a certain amount of jitter from shitty 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)
    • Download linked tar
    • tar -xvf ntpsetup.tar
    • cd ntpsetup.tar
    • ./install.sh
    • This copies the gpscontrol files and creates/enables its service. Also makes a gpsd requirement for ntp
  • 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
stratum1ntp.1563985639.txt.gz · Last modified: 2019/07/24 16:27 by andrew
Back to top
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0