Packet Radio: QtSoundModem Auto-Starting from Systemd

I don’t run the QtSoundModem on the same machine as the node so I use a systemd service script to automatically start up QtSoundModem and put it on a virtual-VNC session that is independent from the physical desktop.

The following systemd scripts call a pair of bash scripts located within the home directory, so that modifications can be done to them without having to reinitialize the systemd service.

Packages Required

sudo apt install realvnc-vnc-server
sudo apt install screen

Note: realvnc is free on the Raspberry Pi, alternatives that may work for other platforms: tightvnc or tigervnc

Systemd Scripts

/lib/systemd/system/qtsm.service


[Unit]
Description=QtSoundModem Start Script
After=vvnc.service
Wants=vvnc.service


[Service]
Type=forking
WorkingDirectory=/home/pi/bin
Restart=always
RestartSec=20
StartLimitInterval=60
StartLimitBurst=3
User=pi
Group=pi
ExecStart=/usr/bin/screen -S QTSM-Console -d -m /home/pi/bin/startqtsm
SyslogIdentifier=QTSM-Debug


[Install]
WantedBy=multi-user.target

/lib/systemd/system/vvnc.service

[Unit]
Description=Shack Desktop Start Script by PE1RRR
After=network.target


[Service]
Type=forking
WorkingDirectory=/home/pi/bin
Restart=always
RestartSec=20
StartLimitInterval=60
StartLimitBurst=3
User=pi
Group=pi
ExecStart=/home/pi/bin/vvnc
SyslogIdentifier=Shack-VNC


[Install]
WantedBy=multi-user.target

Virtual Virtual VNC?

vvnc for virtual-VNC, yep its a virtual virtual desktop, one that runs independently from the default usually found running as a clone of the desktop monitor display.


This script starts a virtual VNC screen that can be attached from any device such as a smart phone, iPad or other desktop Pi.

/home/pi/bin/vvnc

#!/bin/bash
vncserver -kill :1
vncserver :1 -geometry 2732x2048

Set permissions to execute:

chmod 755 /home/pi/bin/vvnc

QtSoundModem Start Script

/home/pi/bin/startqtsm

cd /home/pi/bin

# Launch invisibly
# /home/pi/bin/SM nogui

# Launch with GUI

# Set the display number here. If HDMI connected monitor, this is usually :0

# For VNC sessions, this is determined in the desktop- check it with “echo $DISPLAY” in a shell within the VNC.

DISPLAY=:1
export DISPLAY
/home/pi/bin/QtSoundModem # path to your QtSoundModem binary

Set permissions to execute:

chmod 755 /home/pi/bin/startqtsm

There are a couple of ways of launching QtSoundModem, I prefer to have the GUI to keep and eye on the waterfall and monitor packets etc.. there is an option to start it invisibly in which case- you can opt to use the nogui mode, and remove all references to vvnc.service in the previous scripts as they won’t be needed.

Initialise systemd

Need only doing once:

sudo systemctl enable qtsm.service
sudo systemctl enable vvnc.service

To Stop/Start manually:

sudo service qtsm start

If the vvnc service is not yet running qtsm’’s service will auto-start it for you. This is due to the “Wants=“ directive in qtsm.service.

Restarting the vvnc service will kill any vnc server running on the display defined in the /home/pi/bin/vvnc file before starting up again.

Displaying the VNC Session

If all has gone well, then QtSoundModem should be displayed on your Virtual VNC screen. That is, assuming you’ve connected a VNC client to it to display it!

The common way to connect to the VNC server is using the address and the display number. 0 (zero) nearly always refers to the hardware-wired display, and the first virtual server after that is :1

e.g IP-address:1

vncviewer 192.168.0.44:1

Monitoring the Consoles

As these systemd scripts launch with the screen command, this provides a way to keep an eye on the console output without it thrashing the SD Card with continuous writes. To attach to the running screen console, try the following:

screen -r

If you only have one screen session running then it will re-attach automatically, if not then it will show you a list from which you must provide a string after the -r that can be wildcard-matched either with the process number or the console’s name.