Posted on 1 Comment

Raspberry Pi – Multiple Instances of RTLSDR as a Service

My Raspberry Pi RTL Dongle server cards run the server as a service under systemd. This has several benefits including a better-defined start and the facility to stop/restart a service gracefully. One of my customer recently asked if it was possible to support 2 dongles and switch between them.

From previous tests, I know that a Pi3-B can support up to 4 RTL-SDR server instances, so switching between two should be easy. To add a second instance we just need to create a second Service file that’s a duplicate of the original with just one line changed. Here’s a copy of the original, single device, service file:

[Unit]
Description=RTL-SDR Server

Wants=network-online.target
After=network-online.target

[Service]

ExecStartPre=/bin/sleep 15
ExecStart=/bin/sh -c ‘/usr/local/bin/rtl_tcp -a $(hostname -I)’
WorkingDirectory=/home/pi
StandardOutput=inherit
StandardError=inherit
Restart=always

[Install]
WantedBy=multi-user.target

The line we need to change is the ExecStart as this line actually starts the server. To add another instance it should read:

ExecStart=/bin/sh -c ‘/usr/local/bin/rtl_tcp -a $(hostname -I) -d1 -p1235’

The -d suffix is the device number which counts from 0 and the -p1235 entry forces the second server instance to use port 1235.

Here’s a step-by-step guide to adding a second instance. NB: Back-up your SD card first!

  • Open a terminal session (Ctl-Atl-t)
  • Enter: cd /etc/systemd/system
  • sudo cp rtlsdr.service rtlsdr1.service
  • sudo nano rtlsdr1.service
  • Edit the ExecStart line to add: -d1 -p1235 as in above example
  • Press Ctl-x followed by y to save and close the file
  • Make sure you have two dongles connected to the Pi
  • Enter sudo systemctl start rtlsdr1
  • Enter sudo systemctl status rtlsdr1 This checks the status so you should see your dongle reported
  • If all is well enter: sudo systemctl enable rtlsdr1 This will make the second instance automatically run at boot.

That’s it! If you want to stop either service from starting at boot use: sudo systemctl disable rtlsdr or rtlsdr1

To start or stop a service it’s sudo systemctl stop rtlsdr or rtlsdr1 to start it’s sudo systemctl start rtlsdr or rtlsdr1

Good Luck,

Mike – G4WNC

1 thought on “Raspberry Pi – Multiple Instances of RTLSDR as a Service

  1. Mike,
    How do you change Exec Start line to use a fixed IP address. I am trying to get the RSP1a tcp server running using a version of this Unit File for creating a service to get rsp_tcp service to run for an RSP1a

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.