Packet Radio Interface (Direwolf/APRS to OpenHAB via MQTT)

Recently I have been working on building a rugged packet feed into OpenHAB via MQTT eventbus for several APRS packet radio appliances around my home and some weather sensor arrays that have APRS transmissions on the 2M band.

The work so far centers on a script in systemd to reliably pipe the output from a USB RTL-SDR dongle through Direwolf and into mosquitto_pub. I can catch around 30 minutes of packet information from the local repeaters but I cannot for the life of me get mosquitto_pub to remain stable.

In home/pi/dw-start2.sh:

#!/bin/bash

export LANG=C
PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"

MQTT_HOST=""

rtl_fm -f 144.39M -g 75 - | direwolf -c /home/pi/sdr.conf -r 24000 -D 1 - | while read line

do

echo $line | /usr/bin/mosquitto_pub -h $MQTT_HOST -i APRS -l -t “/openhab/aprs”
echo $line >> /tmp/direwolf.log

done

In /etc/systemd/system/aprs.service:

[Timer]
OnBootSec=4min
[Unit]
Description=Direwolf Packet to MQTT publisher
After=network.target
[Service]
ExecStartPre=-/bin/bash -c “rmmod dvb_usb_rtl28xxu rtl2832”
ExecStart=/bin/bash -c “/home/pi/dw-start2.sh”
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target

Any thoughts or suggestions to help clean this up?

The error you see when mosquitto_pub goes “unstable” would be informative.

I suspect you need to add a sleep 1 or if you have a version of sleep that supports fractional seconds sleep 0.1 at the end of your loop.

Mosquitto doesn’t like the same client to have more than one connection at a time and I suspect it is rejecting the connections that try to start while a previous mosquitto_pub is still doing its work.

There are no visible errors but the process seems to hang. Logfile and MQTT output are the same. This setup works with rtl_433 flawlessly but not with Direwolf. See http://www.marcoach.nl/rtl_433-mqtt-version-2-0/ for the script template I referenced.

Here’s the MQTT output of the process:

Now connected to IGate server (EDITEDOUT)
Check server status here http://EDITEDOUT:14501
[ig] # aprsc 2.1.4-*
[ig] # logresp CALLSIGN verified, server TRANSYLVANIA
Channel 0: 1200 baud, AFSK 1200 & 2200 Hz, E+, 24000 sample rate.
Note: PTT not configured for channel 0. (Ignore this if using VOX.)
Use -p command line option to enable KISS pseudo terminal.
Ready to accept AGW client application 0 on port 8000 …
Ready to accept KISS client application on port 8001 …
Can’t get address for IGate server EDITEDOUT, Name or service not known
Can’t get address for IGate server EDITEDOUT, Name or service not known

Now connected to IGate server EDITEDOUT
Check server status here EDITEDOUT
[ig] # aprsc 2.1.4-*
[ig] # logresp CALLSIGN verified, server TRANSYLVANIA

● aprs.service - Direwolf Packet to MQTT publisher
Loaded: loaded (/etc/systemd/system/aprs.service; enabled)
Active: active (running) since Wed 2017-08-30 20:09:45 UTC; 2h 13min ago
Process: 648 ExecStartPre=/bin/bash -c rmmod dvb_usb_rtl28xxu rtl2832 (code=exited, status=0/SUCCESS)
Main PID: 708 (dw-start2.sh)
CGroup: /system.slice/aprs.service
├─708 /bin/bash /home/pi/dw-start2.sh
├─733 rtl_fm -f 144.39M -g 75 -
├─738 direwolf -c /home/pi/sdr.conf -r 24000 -D 1 -
└─739 /bin/bash /home/pi/dw-start2.sh

Aug 30 20:09:48 raspberrypi bash[708]: Unable to connect (15).
Aug 30 20:09:49 raspberrypi bash[708]: Tuner gain set to 49.60 dB.
Aug 30 20:09:49 raspberrypi bash[708]: Tuned to 144642000 Hz.
Aug 30 20:09:49 raspberrypi bash[708]: Oversampling input by: 42x.
Aug 30 20:09:49 raspberrypi bash[708]: Oversampling output by: 1x.
Aug 30 20:09:49 raspberrypi bash[708]: Buffer size: 8.13ms
Aug 30 20:09:49 raspberrypi bash[708]: Exact sample rate is: 1008000.009613 Hz
Aug 30 20:10:08 raspberrypi bash[708]: r82xx_write: i2c wr failed=-9 reg=0b len=1
Aug 30 20:10:08 raspberrypi bash[708]: Sampling at 1008000 S/s.
Aug 30 20:10:08 raspberrypi bash[708]: Output at 24000 Hz.

So have you added the sleep to your loop or not?

Yes. No effect. I added sleep 1 to the end of the loop.