I originally posted to see if anyone had worked out how to send all received ADS-B data from a Pi running the ADSBx image with the official blue dongle to an MQTT server for use in other systems like via NodeRed and for Home Assistant.
I didn’t get a response, so ChatGPT to the rescue.
The below is the final instructions after about 40 mins of going back and forth, hitting errors and solving them.
Instructions…
How to Stream ADS-B Aircraft Data from Raspberry Pi to MQTT for Node-RED
This guide explains how to decode ADS-B aircraft signals on a Raspberry Pi Zero 2W with an RTL-SDR dongle and publish live aircraft data to MQTT, ready for use in Node-RED or home automation.
Prerequisites
- Raspberry Pi Zero 2W
- RTL-SDR dongle running
readsb
- MQTT broker on your network (e.g.
10.10.50.8:1883
) - Python 3 installed
- Network access between Pi and broker
Step 1: Verify readsb
is running and outputting JSON
Make sure your readsb
is started with:
css
CopyEdit
--net-json-port 30154
Check the service:
lua
CopyEdit
sudo systemctl status readsb
Check the port is open:
perl
CopyEdit
sudo netstat -tlnp | grep 30154
You should see something like:
nginx
CopyEdit
tcp 0 0 0.0.0.0:30154 0.0.0.0:* LISTEN 476/readsb
Then test the output:
swift
CopyEdit
printf "GET /data/aircraft.json\r\n\r\n" | nc localhost 30154
You should get JSON lines, one per aircraft.
Step 2: Understand the JSON format
The feed is newline-delimited JSON objects, not a JSON array. You must parse it line-by-line.
Step 3: Create the ADS-B → MQTT bridge script
Save this as:
swift
CopyEdit
/usr/local/bin/adsb-to-mqtt.py
Paste this full code:
python
CopyEdit
#!/usr/bin/env python3
import socket
import json
import time
import paho.mqtt.client as mqtt
MQTT_BROKER = "10.10.50.8" # ← Your MQTT broker IP
MQTT_PORT = 1883
MQTT_TOPIC = "adsb/aircraft"
HOST = "localhost"
PORT = 30154
def fetch_and_publish(client):
try:
with socket.create_connection((HOST, PORT), timeout=5) as s:
s.sendall(b"GET /data/aircraft.json\r\n\r\n")
buffer = b""
while True:
chunk = s.recv(4096)
if not chunk:
break
buffer += chunk
while b"\n" in buffer:
line, buffer = buffer.split(b"\n", 1)
if line.strip():
try:
aircraft = json.loads(line)
client.publish(MQTT_TOPIC, json.dumps(aircraft))
print(f"Published: {aircraft.get('hex')} → {aircraft.get('flight')}")
except json.JSONDecodeError:
print("Bad JSON:", line)
except Exception as e:
print("Socket error:", e)
def main():
client = mqtt.Client(protocol=mqtt.MQTTv311)
client.connect(MQTT_BROKER, MQTT_PORT, 60)
while True:
fetch_and_publish(client)
time.sleep(5)
if __name__ == "__main__":
main()
Make it executable:
bash
CopyEdit
sudo chmod +x /usr/local/bin/adsb-to-mqtt.py
Test it:
swift
CopyEdit
python3 /usr/local/bin/adsb-to-mqtt.py
If successful, you’ll see logs of published aircraft in the terminal.
Step 4: Install the MQTT Python client globally
css
CopyEdit
sudo pip3 install --upgrade --force-reinstall paho-mqtt
Verify:
sql
CopyEdit
python3 -m pip show paho-mqtt
Step 5: Set it up to run at boot with systemd
Create the service file:
swift
CopyEdit
sudo nano /etc/systemd/system/adsb-mqtt.service
Paste:
ini
CopyEdit
[Unit]
Description=ADSB to MQTT Bridge
After=network.target
[Service]
ExecStart=/usr/bin/python3 /usr/local/bin/adsb-to-mqtt.py
Restart=always
User=pi
WorkingDirectory=/home/pi
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=adsb-mqtt
[Install]
WantedBy=multi-user.target
Make sure
User=
andWorkingDirectory=
match your setup.
Reload and start it:
pgsql
CopyEdit
sudo systemctl daemon-reload
sudo systemctl enable adsb-mqtt.service
sudo systemctl start adsb-mqtt.service
Check status:
lua
CopyEdit
sudo systemctl status adsb-mqtt.service
Live logs:
nginx
CopyEdit
sudo journalctl -f -u adsb-mqtt.service
Troubleshooting
Problem | Fix |
---|---|
No data from port 30154 | Make sure readsb is running and has --net-json-port 30154 |
No aircraft received | Check SDR, gain, antenna, or reception conditions |
Script fails in systemd | Make sure paho-mqtt is installed system-wide (sudo pip3 install ) |
MQTT not receiving data | Confirm broker IP/port and firewall; test script manually first |
Result
Each aircraft is published individually to MQTT topic:
bash
CopyEdit
adsb/aircraft
You can now connect this in Node-RED, Home Assistant, or any MQTT-aware system