1

I have a Raspberry Pi 3 B+ with Adafruit Ultimate GPS HAT (https://www.adafruit.com/product/2324) with external antenna. I configured the device to act as NTP server but the NTP server won't work (No client can sync to it and I get an error) unless I have additional internet time server such as

pool 0.debian.pool.ntp.org iburst

my ntp.conf setting for the GPS and PPS is as follow:

server 127.127.20.0 iburst true prefer 
fudge 127.127.20.0 flag1 1 refid GPSD
server 127.127.22.0 iburst true prefer 
fudge 127.127.22.0 flag1 1 refid KPPS

/etc/default/gpsd file is as follow:

# 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/serial0 /dev/pps0"

# Other options you want to pass to gpsd
# -n    don't wait for client to connect; poll GPS immediately
GPSD_OPTIONS="-n"

/boot/config.txt I added the following lines:

force_turbo=1
dtoverlay=pps-gpio,gpiopin=4
init_uart_baud=9600
arm_freq=800

/boot/cmdline.txt was modified to look like this:

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait splash plymouth.ignore-serial-consoles

/etc/modules was modified to like like this:

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

i2c-dev
pps-gpio

/etc/rc.local has been modified to look like this:

  GNU nano 2.7.4                                                             File: /etc/rc.local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

ln -s /dev/serial0 /dev/gps0
service gpsd stop
service ntp restart

exit 0

when I query ntpq -pn, the result is:

pi@raspberrypi:~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 127.127.20.0    .GPSD.           0 l    -   64    0    0.000    0.000   0.000
x127.127.22.0    .KPPS.           0 l  156   64   54    0.000  -30.909   6.705
 0.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.001
+212.26.18.43    209.51.161.238   2 u   24   64  377   63.087   -3.832  11.598
+212.26.18.41    209.51.161.238   2 u   55   64  377   62.326   -2.398  38.556
*212.138.170.134 .PPS.            1 u   56   64  377   93.082    0.377  39.534

When I test PPS, I get the following data:

pi@raspberrypi:~ $ sudo ppstest /dev/pps0
trying PPS source "/dev/pps0"
found PPS source "/dev/pps0"
ok, found 1 source(s), now start fetching data...
source 0 - assert 1556386700.020399338, sequence: 182 - clear  0.000000000, sequence: 0
source 0 - assert 1556386701.020371974, sequence: 183 - clear  0.000000000, sequence: 0
source 0 - assert 1556386702.020344473, sequence: 184 - clear  0.000000000, sequence: 0

1
  • I have set -n in GPSD_OPTIONS but I have to manually run cgps to get NTP working.
    – JPX
    Oct 29, 2022 at 21:53

1 Answer 1

2

Whilst historically I've used the built in ntpd GPS drivers, these have become increasingly dated and buggy with newer hardware. More recently I've therefore moved from 127.127.20.0 to the shared memory driver 127.172.28.0.

This allows you to keep gpsd running (so you need to remove the "service gpsd stop" from rc.local), and gives potentially much better diags.

If you make this change and it doesn't "just work", a good next step is to install "gpsd-clients" and run the command "cgps". This will show you whether gpsd has correctly identified the GPS receiver, and whether it has got a lock. It will also show ongoing status messages from your receiver.

If cgps doesn't show live data, you need to start by digging into the gpsd config, where there can be issues with baud rate and startup order.

Alternatively, if you find that ntp works after you've used cgps, but not on reboot, you've got an issue with the startup config for gpsd. Have a look here https://gpsd.gitlab.io/gpsd/troubleshooting.html for guidance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.