=====Raspberry Pi, Dragino LoRa / GPS hat - NTP PPS=====
Configure NTPd with PPS. Based on Raspbian Stretch.
**Notes:**
* Could not get PPS to work with the new refclock driver 46, GPSD NG client protocol. Switched to PPS (22) and SHM (28).
* GPSd did not auto start at boot, added the driver above with ''noselect'' to get GPSd to start.
**Sources:**
* [[https://www.eecis.udel.edu/~mills/ntp/html/refclock.html]]
* [[https://www.slsmk.com/how-to-setup-a-gps-pps-ntp-time-server-on-raspberry-pi/]]
{{:lora_gps_hat1.png?400|}}
====Configure Raspberry Pi====
Based on Raspbian Stretch
* Disable hardware; Wifi, Bluetooth, HDMI.
* Disable services; avahi, triggerhappy, wpa_supplicant
* Add user, remove pi user.
* Set correct timezone.
* Update packages.
====Configure serial port====
* Disable Bluetooth:echo "dtoverlay=pi3-disable-bt" >> /boot/config.txt
* Disable the HCI UART:sudo systemctl disable hciuart
* Disable getty:systemctl mask serial-getty@serial0.service
* Remove ''console=serial0,115200'' from ''/boot/cmdline.txt''
* Reboot
* Test GPS output: ''cat /dev/serial0''
====Configure Pulse Per Second (PPS)====
* Install PPS tools:apt install pps-tools setserial
* Configure GPIO for PPS:echo "dtoverlay=pps-gpio,gpiopin=18" >> /boot/config.txt
* Configure udev rules in ''/etc/udev/rules.d/gps.rules''
KERNEL=="ttyAMA0", RUN+="/bin/setserial /dev/ttyAMA0 low_latency"
KERNEL=="ttyAMA0", SYMLINK+="gps0"
KERNEL=="pps0", GROUP="dialout", MODE="0660"
* Reboot
* There should be a ''/dev/pps0'' device
* Check for pulse# 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 1552847111.000139273, sequence: 152 - clear 0.000000000, sequence: 0
source 0 - assert 1552847112.000135096, sequence: 153 - clear 0.000000000, sequence: 0
source 0 - assert 1552847113.000135337, sequence: 154 - clear 0.000000000, sequence: 0
source 0 - assert 1552847114.000134886, sequence: 155 - clear 0.000000000, sequence: 0
source 0 - assert 1552847115.000135615, sequence: 156 - clear 0.000000000, sequence: 0
source 0 - assert 1552847116.000137416, sequence: 157 - clear 0.000000000, sequence: 0
====Configure GPdS====
* Install packages:apt install gpsd gpsd-clients
* Configure devices and options in ''/etc/default/gpsd''DEVICES="/dev/ttyAMA0"
GPSD_OPTIONS="-n"
* Reboot
* Test GPS output with ''cgps'' or ''gpsmon''.
====Configure NTPd====
* Disable systemd timesyncd:systemctl stop systemd-timesyncd
systemctl disable systemd-timesyncd
* Install required packages:sudo apt install libcap-dev
* Install NTP:
# Download latest from http://www.ntp.org/downloads.html
curl -OL http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p13.tar.gz
tar zxvf ntp-4.2.8p13.tar.gz
cd ntp-4.2.8p13
./configure --enable-linuxcaps
make -j4
sudo make install
sudo cp /home/user/ntp-4.2.8p13/scripts/rc/ntpd /etc/init.d/
# Modify ntpd location in /etc/init.d/ntpd, and add lines below above variables.
### BEGIN INIT INFO
# Provides: ntpd
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: NTPD
### END INIT INFO
groupadd ntp
useradd -d /var/lib/ntp -g ntp -s /bin/false ntp
printf 'PATH=${PATH}:/usr/local/bin\n' > /etc/profile.d/ntp-path.sh
install -v -o ntp -g ntp -d /var/lib/ntp
systemctl enable ntpd
* Add to ''/etc/ntp.conf''
# PPS
server 127.127.22.0 minpoll 4 maxpoll 4 true
fudge 127.127.22.0 flag3 1 refid PPS
# GPS Serial, GPSD SHM
server 127.127.28.0 minpoll 4 maxpoll 4 iburst prefer
fudge 127.127.28.0 flag1 1 time1 0.200 refid SHM0 stratum 1
# PPS, GPSD SHM
server 127.127.28.2 minpoll 4 maxpoll 4
fudge 127.127.28.2 flag1 1 refid SHM2
# GPSD JSON driver, to auto start GPSD
server 127.127.46.0 minpoll 4 maxpoll 4 noselect
# Fix False tickers
tos mindist 0.5
* Enable and start ntpd:systemctl enable ntp
systemctl start ntp
* Comment ntp option in ''/etc/dhcpcd.conf''#option ntp_servers
* Reboot
{{tag>[lora dragino gps ntp hat]}}