Overview
If you ever wanted to setup a Raspberry Pi as a ADSB, Stratum 1 and network server, you've come to the right place. We'll run you through what hardware and software you'll need and how to set it up.Table of Contents
- Hardware
- Software
- Hardware Setup
- Software Installation
|- Pi Installation
|- Pi Setup
|- Tools Installation
|- Dump1090
- Configuration |- /boot/firmware/cmdline.txt
- Reboot
- Testing |- Starting the services
- Conclusion
|- /boot/firmware/config.txt
|- /etc/modules
|- /etc/network/interfaces
|- /etc/default/gpsd
|- /etc/systemd/system/gpsd.socket
|- /lib/systemd/system/gpsd.socket
|- /etc/default/dnsmasq
|- /etc/dnsmasq/dnsmasq.conf
|- /etc/default/ntpsec
|- /etc/ntpsec/ntp.conf
|- /etc/default/hostapd
|- /etc/hostpad/hostpad.conf
|- /etc/default/shorewall
|- /etc/shorewall/shorewall.conf
|- /etc/shorewall/*
|- Pulse Per Second
|- Global Positioning System
|- Testing Dump1090
|- Enable the services
The Hardware
You'll need ...- A Raspberry Pi 0/4/5 (Pi Hit)
- A GPS board with PPS (Amazon)
- A GPS Antenna (Pi Hit)
- A ADSB Antenna (Pi Hit)
- A SDR (Neolec)
- SD Card (Pi Hit)
The Software
You'll install ...- Raspbian OS
- gpsmon Location and Time
- hostapd Wifi Access Point
- dnsmasq DHCP and DNS Server ( Network services)
- ntpsec NTP Server ( Stratum 1)
- shorewall Firewall / Router
Hardware Setup
The most important part of the setup is wirring the GPS board to the Raspberry Pi. The following diagram shows the pinout.--------------------- ------------- | Pi Zero | | GPS Board | |-------------------| |-----------| | Pin 2 5V Power | | | | Pin 4 5V Power |<-------->| VCC | | Pin 6 Ground |<-------->| GND | | Pin 8 GPIO 14 TX |<-------->| RX | | Pin 10 GPIO 15 RX |<-------->| TX | | Pin 12 GPIO 18 |<-------->| PPS | --------------------- -------------
Software Installation
Raspberry Pi
The first thing you'll need to do is install the latest version of Raspbian OS. We would recommend using the Raspberry Pi Imager to do this but we prefer to download the image and"dd"
it across with
dd of=/dev/sd? if=2024-03-15-raspios-bookworm-arm64-full.img bs=4M status=progress
Raspberry Setup
Once the Pi OS has been installed, booted and localised you'll need to choose some basicraspi-config
options.
Interfaces -> SSH -> Would you like the SSH server to be enabled -> Yes Interfaces -> Serial Port -> Login shell over serail -> No Interfaces -> Serial Port -> Serial port hardware to be enabled -> Yes Advanced Options -> Network Interface Names -> Enable predictable network interface names -> Yes Finish -> Reboot -> Yes
Tools
Now we need to install some tools. Here's the commands you'll need to run.sudo apt update sudo apt upgrade sudo apt install vim gpsd gpsd-clients hostapd dnsmasq ntpsec shorewall git build-essential cmake libusb-1.0-0-dev librtlsdr-dev librtlsdr0 rtl-sdr pipenvThis will be a good to time to reboot incase the upgrade or update needs to relaod something
sudo reboot
Dump1090
To install dump1090, the ADSB decoder, you will need to ...sudo apt install librtlsdr-dev git clone https://github.com/antirez/dump1090.git cd dump1090 makeTo start dump1090 at boot and the following line to /etc/rc.local ...
cd /home/pi/dump1090/ && ./dump1090 --net 2>/dev/null 1>&2 &
The Configuration
The configuration is the tricky part but the following steps should get you up and running. Note that you will need to use an editor such as nano or vi to edit these files and nano would be the preferred choice but vim is a better option. To use vim you will have to install it withsudo apt install vim
/boot/firmware/cmdline.txt
Add the following option to to the kernel boot options in the/boot/firmware/cmdline.txt
bcm2708.pps_gpio_pin=18
/boot/firmware/config.txt
Add the following options to the/boot/firmware/config.txt
enable_uart=1 dtoverlay=pi3-disable-bt-overlay dtoverlay=pi3-miniuart-bt dtoverlay=disable-bt dtoverlay=pps-gpio,gpiopin=18
/etc/modules
Add the following module to the/etc/modules
pps-gpio
/etc/network/interfaces
Ues the following config for//etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8) # Include files from /etc/network/interfaces.d: source /etc/network/interfaces.d/* auto eth0 allow-hotplug eth0 iface eth0 inet dhcp # Setup static address for the Hostapd auto wlan0 allow-hotplug wlan0 iface wlan0 inet static address 10.10.17.1 netmask 255.255.255.0
/etc/default/gpsd
Use the following configuration for/etc/default/gpsd
DEVICES="/dev/ttyAMA0 /dev/pps0" GPSD_SOCKET="/var/run/gpsd.sock" GPSD_OPTIONS="-n -G -r -b" START_DAEMON="true" USBAUTO="true"
/etc/systemd/system/gpsd.socket
Use the following configuration for/etc/systemd/system/gpsd.socket
[Unit] Description=GPS (Global Positioning System) Daemon Sockets [Socket] #ListenStream= ListenStream=/var/run/gpsd.sock ListenStream=[::1]:2947 ListenStream=0.0.0.0:2947 ## To allow gpsd remote access, start gpsd with the -G option and ## uncomment the next two lines: ##ListenStream=[::]:2947 SocketMode=0600 # BindIPv6Only=no [Install] WantedBy=sockets.target
/lib/systemd/system/gpsd.socket
Use the following configuration for/lib/systemd/system/gpsd.socket
[Unit] Description=GPS (Global Positioning System) Daemon Sockets [Socket] ListenStream=/run/gpsd.sock ListenStream=[::1]:2947 ListenStream=127.0.0.1:2947 ## To allow gpsd remote access, start gpsd with the -G option and ## uncomment the next two lines: ##ListenStream=[::]:2947 SocketMode=0600 BindIPv6Only=yes [Install] WantedBy=sockets.target
/etc/default/dnsmasq
Nothing to change in/etc/default/dnsmasq
/etc/dnsmasq/dnsmasq.conf
Here is a working example of/etc/dnsmasq/dnsmasq.conf
. Note the IP address as this is used
in the network configuration and the hostapd configuration.
listen-address=127.0.0.1,10.10.17.1 resolv-file=/etc/resolv.conf dhcp-authoritative except-interface=eth0 interface=wlan0 addn-hosts=/etc/hosts bind-interfaces domain-needed bogus-priv expand-hosts domain=gpsant local=/.gpsant/ cache-size=1000 dhcp-range=lan,10.10.17.2,10.10.17.254,2h dhcp-option=lan,121,10.10.17.0/24,10.10.17.1 dhcp-option=lan,option:ntp-server,10.10.17.1
/etc/default/ntpsec
Use the following configuration for/etc/default/ntpsec
NTPD_OPTS="-g" IGNORE_DHCP="yes" NTPSEC_CERTBOT_CERT_NAME=""
/etc/ntpsec/ntp.conf
Use the following configuration for/etc/ntpsec/ntp.conf
driftfile /var/lib/ntpsec/ntp.drift leapfile /usr/share/zoneinfo/leap-seconds.list refclock shm unit 1 refid PPS0 refclock shm unit 0 refid GPS0 server 127.127.22.0 minpoll 4 maxpoll 4 iburst fudge 127.127.22.0 refid PPS0 restrict -4 default kod nomodify limited restrict 192.168.0.0/8 restrict 10.10.0.0/8 restrict 127.0.0.1 restrict ::1
/etc/default/hostapd
Use the following configuration for/etc/default/hostapd
DAEMON_OPTS="-T -i wlan0"
/etc/hostapd/hostpad.conf
Use the following configuration for/etc/hostapd/hostpad.conf
hw_mode=g channel=6 ieee80211d=1 country_code=GB ieee80211n=1 wmm_enabled=1 driver=nl80211 ssid="YOUR_SSID_NAME" auth_algs=1 wpa=2 wpa_passphrase="YOUR_SSID_PASSWORD" ignore_broadcast_ssid=0 # 0 = visible, 1 = hidden wpa_key_mgmt=WPA-PSK rsn_pairwise=CCMP
/etc/default/shorewall
Configuring shorewall has the potential to lock you out of SSH access so be careful or at least have direct access with a keyboard and screen.startup=1
/etc/shorewall/shorewall.conf
Change the following option in/etc/shorewall/shorewall.conf
so shorewall will start
STARTUP_ENABLED=Yes
/etc/shorewall/*
The following configuration files need adding to the/etc/shorewall
directory.
# /etc/shorewall/interfaces ?FORMAT 2 ############################################################################### #ZONE INTERFACE OPTIONS lan eth0 dhcp yfi wlan0 dhcp # /etc/shorewall/zones ############################################################################### #ZONE TYPE OPTIONS IN_OPTIONS OUT_OPTIONS fw firewall lan ip yfi ip # /etc/shorewall/policy ############################################################################### #SOURCE DEST POLICY LOGLEVEL RATE CONNLIMIT fw all ACCEPT lan all ACCEPT yfi all ACCEPT all all REJECT # /etc/shorewall/rules ###################################################################################################################################### #ACTION SOURCE DEST PROTO DPORT SPORT ORIGDEST RATE USER MARK CONNLIMIT TIME HEADERS SWITCH HELPER ?SECTION ALL ?SECTION ESTABLISHED ?SECTION RELATED ?SECTION INVALID ?SECTION UNTRACKED ?SECTION NEW # /etc/shorewall/snat ?FORMAT 2 ####################################################################################################################### #ACTION SOURCE DEST PROTO DPORT SPORT IPSEC MARK USER SWITCH ORIGDEST PROBABILITY MASQUERADE 10.10.17.0/24 eth0
Reboot
Now would be a good time to reboot for the some of the key changes to take effect.Testing
Now that we have everything installed and configured everythinbg we can test the setup. Lets try and start the services and check the logs for its status.Testing
# Reload Configs systemctl daemon-reload # GPSD systemctl start gpsd systemctl status gpsd >>● gpsd.service - GPS (Global Positioning System) Daemon >> Loaded: loaded (/lib/systemd/system/gpsd.service; enabled; preset: enabled) >> Active: active (running) since Tue 2024-05-21 08:32:03 BST; 1 week 4 days ago >>TriggeredBy: ● gpsd.socket >> Process: 296 ExecStart=/usr/sbin/gpsd $GPSD_OPTIONS $OPTIONS $DEVICES (code=exited, status=0/SUCCESS) >> Main PID: 304 (gpsd) >> Tasks: 4 (limit: 387) >> CPU: 3min 4.437s >> CGroup: /system.slice/gpsd.service >> └─304 /usr/sbin/gpsd -n -G -r -b /dev/ttyAMA0 /dev/pps0 --------------------- # GPSD Socket systemctl start gpsd.socket systemctl status gpsd.socket ● gpsd.socket - GPS (Global Positioning System) Daemon Sockets Loaded: loaded (/etc/systemd/system/gpsd.socket; enabled; preset: enabled) Active: active (running) since Tue 2024-06-04 11:10:43 BST; 9min ago Triggers: ● gpsd.service Listen: /run/gpsd.sock (Stream) [::1]:2947 (Stream) 0.0.0.0:2947 (Stream) Tasks: 0 (limit: 387) CPU: 11ms CGroup: /system.slice/gpsd.socket --------------------- # HOSTAPD systemctl start hostapd systemctl status hostapd >>● hostapd.service - Access point and authentication server for Wi-Fi and Ethernet >> Loaded: loaded (/lib/systemd/system/hostapd.service; enabled; preset: enabled) >> Active: active (running) since Tue 2024-05-21 08:32:38 BST; 1 week 5 days ago >> Docs: man:hostapd(8) >> Process: 799 ExecStart=/usr/sbin/hostapd -B -P /run/hostapd.pid $DAEMON_OPTS ${DAEMON_CONF} (code=exited, status=0/SUCCESS) >> Main PID: 808 (hostapd) >> Tasks: 1 (limit: 387) >> CPU: 364ms >> CGroup: /system.slice/hostapd.service >> └─808 /usr/sbin/hostapd -B -P /run/hostapd.pid -T -i wlan0 /etc/hostapd/hostapd.conf --------------------- # SHOREWALL systemctl start shorewall systemctl shorewall >>● shorewall.service - Shorewall IPv4 firewall >> Loaded: loaded (/lib/systemd/system/shorewall.service; enabled; preset: enabled) >> Active: active (exited) since Tue 2024-05-21 08:32:49 BST; 1 week 5 days ago >> Docs: man:shorewall(8) >> Process: 804 ExecStart=/sbin/shorewall $OPTIONS start $STARTOPTIONS (code=exited, status=0/SUCCESS) >> Main PID: 804 (code=exited, status=0/SUCCESS) >> CPU: 2.006s --------------------- # DNSMASQ systemctl start dnsmasq systemctl status dnsmasq >>● dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server >> Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled; preset: enabled) >> Active: active (running) since Tue 2024-05-21 08:32:43 BST; 1 week 5 days ago >> Process: 798 ExecStartPre=/etc/init.d/dnsmasq checkconfig (code=exited, status=0/SUCCESS) >> Process: 867 ExecStart=/etc/init.d/dnsmasq systemd-exec (code=exited, status=0/SUCCESS) >> Process: 883 ExecStartPost=/etc/init.d/dnsmasq systemd-start-resolvconf (code=exited, status=0/SUCCESS) >> Main PID: 881 (dnsmasq) >> Tasks: 1 (limit: 387) >> CPU: 595ms >> CGroup: /system.slice/dnsmasq.service >> └─881 /usr/sbin/dnsmasq -x /run/dnsmasq/dnsmasq.pid -u dnsmasq -7 /etc/dnsmasq.d,.dpkg-dist,.dpkg-old,.dpkg-new --local-service ... --------------------- # NTPSEC systemctl start ntpsec systemctl status ntpsec >>● ntpsec.service - Network Time Service >> Loaded: loaded (/lib/systemd/system/ntpsec.service; enabled; preset: enabled) >> Active: active (running) since Sun 2024-06-02 07:54:58 BST; 32min ago >> Docs: man:ntpd(8) >> Process: 1051 ExecStart=/usr/libexec/ntpsec/ntp-systemd-wrapper (code=exited, status=0/SUCCESS) >> Main PID: 1054 (ntpd) >> Tasks: 1 (limit: 387) >> CPU: 1.951s >> CGroup: /system.slice/ntpsec.service >> └─1054 /usr/sbin/ntpd -p /run/ntpd.pid -c /etc/ntpsec/ntp.conf -g -u ntpsec:ntpsec ---------------------
Pulse Per Second Testing
To test PPS the use the following command ...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 1717496861.999777250, sequence: 11818 - clear 0.000000000, sequence: 0 >> source 0 - assert 1717496862.999787146, sequence: 11819 - clear 0.000000000, sequence: 0
Testing GPS
To test GPS the use the following command ...gpsmon >> tcp://localhost:2947 NMEA0183> >> ┌────────────────────────────────────────────────────────────────────────────┐ >> │Time: 2024-06-04T10:32:56.000Z Lat: 52 29.820790' N Lon: 1 03.292980' E │ >> └───────────────────────────────── Cooked TPV ─────────────────────────────────┘ >> ┌────────────────────────────────────────────────────────────────────────────┐ >> │ GPGGA GPGSA GPGSV GPGLL GPRMC GPVTG │ >> └───────────────────────────────── Sentences ──────────────────────────────────┘ >> ┌───────────────────────┌────────────────────────┌──────────────────────────┐ >> │GP 1 1 162 9 0 N │Latitude: 5229.82079 N │Latitude: 5229.82082 │ >> │GP 2 2 244 5 26 N │Longitude: 00103.29298 E |Longitude: 00103.29296 │ >> │GP 7 7 298 17 40 N │Speed: 0.003 │Altitude: 60.0 │ >> │GP 8 8 289 51 29 N │Course: │Quality: 1 Sats: 11 │ >> │GP 10 10 135 48 17 N │Status: A FAA:A │HDOP: 0.78 │ >> │GP 10 10 135 48 27 N │MagVar: │Geoid: 45.8 │ >> │GP 13 13 8 5 11 N └───────── RMC ───────────└─────────── GGA ──────────┘ >> │GP 13 13 7 5 36 N ┌─────────────────────────┌──────────────────────────┐ >> │GP 15 15 36 10 26 N │Mode: A3 Sats: │UTC: RMS: │ >> │GP 15 15 36 10 41 N │DOP H=0.78 V=1.04 P=1.30 │MAJ: MIN: │ >> │GP 16 16 186 49 25 N │TOFF: 0.152009469 │ORI: LAT: │ >> │GP 16 16 186 49 28 N │PPS: -0.000225011 │LON: ALT: │ >> └───v──── GSV ──────────└────── GSA + PPS ──────────└─────────── GST ──────────┘
Dump1090 Testing
To Be Continued ...- Testing
- Startup script for systemd
Enable Servcies to start at boot
If all has gone well you should now be able to enable the services to start at boot.sudo systemctl enable gpsd sudo systemctl enable gpsd.socket sudo systemctl enable hostapd sudo systemctl enable dnsmasq sudo systemctl enable ntpsec sudo systemctl enable shorewall
Conclusion
If everything went according to plan then you will have a Raspberry Pi that is a Stratum 1 NTP server, a ADSB server and a network server. Diagram of the setup below.(o_ ( ) //\ |\^^/| \_/_ (O::O) ----------------\\//- Penguin Dragon (oo) ---------------------