A potential work-around for multiple RTL devices with their own spyserver

Show off any of your RTL-SDR or cheap SDR related projects.
Post Reply
Timpanogos Slim
Posts: 14
Joined: Mon Feb 10, 2020 1:39 am

A potential work-around for multiple RTL devices with their own spyserver

Post by Timpanogos Slim » Mon Feb 10, 2020 5:38 am

My vague plan at the moment is to have three rtl-sdr devices hung off of an allwinner h5 SBC. Each SDR will have its own usb bus, because that's a feature of the H5 - multiple usb host adapters. Based on my experiments tonight with a single SDR, three won't stress the cpu.

Here and elsewhere, the question of how to associate a specific RTL-SDR with a specific instance of spyserver seems to have always been "there's not a good way to do it" and that's probably the designed functionality since spyserver is really for airspy devices.

Multiple sources say that the serial number line in spyserver.config is only used when the device type is an airspy device.

The only exception to that, that I've seen, is another post on this forum, here:

viewtopic.php?t=1861

"He did it right for 0 and 1 when he didn't prepend 0x"

I might try it but I'm gonna be skeptical for now.

Right now i have two sdr devices. My old e4000 dvb-t stick has a long serial number and no eeprom. my v3 rtl-sdr.com dongle of course has an eeprom and a default serial number of "1" which can be changed to anything.

read more about udev rules here: https://wiki.debian.org/udev

It turns out that the serial number is an attribute that can be used in a udev rule because it is reported through that api.

The udev rules that we've all been installing on our linux systems just make it so that every unprivileged user can utilize every sdr which is a good start.

I think I can write udev rules such that each individual rtl dongle gets assigned permissions so that it is only readable by a specific user.

Then each instance of spyserver will run as one of those users, and hopefully the "first available" sdr device for each of them is simply the only one that they can access, and it doesn't fall on its face when it tries to find sdr devices and can't open them.

Timpanogos Slim
Posts: 14
Joined: Mon Feb 10, 2020 1:39 am

Re: A potential work-around for multiple RTL devices with their own spyserver

Post by Timpanogos Slim » Tue Feb 11, 2020 9:54 pm

Now that i've been playing with it for a couple days, i have to admit i had no idea how hard it is to keep two instances of spyserver both configured for rtl-sdr from stepping on each other's toes.

it looks like when you start it up it walks sysfs to find the "first available" rtl-sdr, which turns out to mean any rtl-sdr even if the device is already locked e.g. not even available.

So your first and second instances both try to use the device with index 0.

I have not found any evidence to suggest that it can be convinced to do otherwise.

Probably a better idea to just dedicate an orange pi zero to each sdr if you want a small low power remote headless server.

LotarInc
Posts: 1
Joined: Tue Aug 11, 2020 7:54 pm

Re: A potential work-around for multiple RTL devices with their own spyserver

Post by LotarInc » Tue Aug 11, 2020 8:42 pm

Hi there,

I'm trying to setup two sdrs with different antennas (discone and HF longwire) on the same Raspberry pi

Did you managed to make two instances of spyserver play nice with two rtl_sdrs?
I'm currently struggling to make it work. I changed (rtl_eeprom) the serial numbers on both sdrs and setup different config files for each SDR.

My sdrs are now sn 00000101 and sn 00000102 specifically.
In both config files (second one as example), I setup the serial

as decimal
device_serial = 00000102

as decimal (short)
device_serial = 102

and hex
device_serial = 66

and (full lenght) hex
device_serial = 0x0000000000000066

Even tried the usb Device ID
device_serial = 005

Unfortunately, spyserver appeaser to not "find" my sdrs by their specific SNs, whatever variant I try. (i'm probably missing something very obvious here :? )

It hangs on
Listening for connections
not finding the SDR which would result in
Found Rafael Micro R820T tuner
[R82XX] PLL not locked!


The only way to make it work (a single instance) is to set device_serial = 0 and let spyserver find the first available device (which is somewhat misleading in the info section of the config file, as spyserver looks for the first device, not taking into account if it is available or not. Probably with official airspy hardware it works as advertised)

Letting device_serial = 0 results in one instance (first one) running fine grabbing one of the two sdrs available and the second one in perpetual limbo trying to connect to the same sdr...

Any help would be appreciated :)

blankA
Posts: 1
Joined: Mon Dec 07, 2020 10:18 pm

Re: A potential work-around for multiple RTL devices with their own spyserver

Post by blankA » Mon Dec 07, 2020 10:47 pm

It's disheartening this hasn't been answered, my own conclusion is that it isn't possible to select by serial numbers outside of Airspy's hardware. Being that the RTLs S/N is decimal and the server needs a hex value. I'm in the testing stage for an outdoor based PoE powered Pi4 based receiver set and since the SDRs are cheap and the Pi4 has 4 ports I might as well fill them up. The main is for a wideband discone to be split and a second SDR dedicated to an up converter (ham it up because it's cheap), a flightaware SDR for ADS-B, and the other is likely to be trunk tracking. I do have an R2 and spyverter for mobile use but they are too expensive to throw outside in longterm testing for a project that could be killed by a lightning strike or destroyed by weather/moisture. It's not really a realistic option to go out every time the Pi power cycles and play the unplug goat rope with VNC just to get the right device per instances of spyserver especially because I wanted to use it with a VPN while I was away. dump1090 does allow picking a device by index which while not ideal is an improvement. I do appreciate your suggestion about multiple Orange Pi I'd have to put a PoE Passthrough Switch out there to power them though, perhaps that's the best option to avoid spyserver issues but keeping up with 4 separate hosts would be no less of a hassle perhaps more.

I do wish they would allow the spyserver to accept decimal serial numbers...

greenbird
Posts: 1
Joined: Sun Feb 14, 2021 8:15 pm

Re: A potential work-around for multiple RTL devices with their own spyserver

Post by greenbird » Sun Feb 14, 2021 9:37 pm

greetings! signed up just to provide my solution to this problem. 8-)

first, a few things I've learned & discovered:
  • in spyserver.config, when "device_type = RTL-SDR", the setting "device_serial" does not refer to the serial number of the RTL-SDR, but rather the device index. this is the same device index as the "-d" parameter for the rtl_eeprom suite of programs. so for example, if "rtl_eeprom -d 2" refers to your desired target device, then specify "device_serial = 2" in spyserver.config.
  • Derusha Digital Designs has written a nice little script that takes an RTL-SDR dongle serial number and figures out the corresponding device index. this script is especially helpful because the device index for a specific dongle can change between system reboots (what was device index 2 today may be device index 0 tomorrow). the script works by going through each of your RTL-SDR dongles and then comparing its serial number to the one you've supplied. if a dongle matches, JUST the index number (e.g. 0, 1, 2, etc.) is returned.
  • the Unix sed command can be used to substitute placeholders in a configuration file for actual values. for example, if our target device index is 5 and we used ${device_index} as a placeholder in spyserver.config for the "device_serial" line:

    Code: Select all

    # Device Serial Number as 64bit Hex
    # For example: 0xDD52D95C904534AD
    # A value of 0 will acquire the first available device.
    #
    # IMPORTANT: For RTL-SDR, device_serial refers to device index
    #
    device_serial = ${device_index}
    and then issued the following command:

    Code: Select all

    sed -e "s/\${device_index}/5/" spyserver.config
    we would see in the resulting output that the "device_serial" line is substituted as:

    Code: Select all

    device_serial = 5
chaining all of the above together, my solution is as follows...
  • rename spyserver.config as spyserver.config.template
  • change the line device_serial = _ to device_serial = ${device_index} in spyserver.config.template
  • create a new script as start_spyserver.sh

    Code: Select all

    #!/bin/sh
    
    # specify target device serial number
    DEVICE_SERIAL="00000102"
    
    # determine device index given serial number
    DEVICE_INDEX=`rtlsn2dev.sh $DEVICE_SERIAL`
    
    # remove existing config file
    rm -f spyserver.config
    
    # substitute value in template
    sed -e "s/\${device_index}/$DEVICE_INDEX/" spyserver.config.template > spyserver.config
    
    # start SPY Server
    spyserver spyserver.config
  • if SPY Server is started automatically at system boot, change your systemd or init.d scripts to execute this script instead of the spyserver daemon directly
  • if you plan to run multiple instances of SPY Server, you could modify the script to output multiple configuration files for each device, or you could change the script to take the serial number as a command line parameter, or you could... etc.
  • you may wish to explicitly specify full paths to all file references above (e.g. /etc/spyserver.config instead of just spyserver.config)
I hope my solution is useful to you. I never actually thought of putting everything together until I read this thread, so thanks to the original poster and respondents for "motivating" me to fix this annoyance in earnest!

hotpaw2
Posts: 176
Joined: Sat Jan 14, 2017 11:07 pm
Contact:

Re: A potential work-around for multiple RTL devices with their own spyserver

Post by hotpaw2 » Mon Feb 15, 2021 7:07 pm

My overly-simplified method of running multiple SDR dongles without any device ID issues is to use a separate Raspberry Pi for each USB dongle. I co-locate the Pi's and SDRs near my antenna distribution panel. Then I run all the networked Pi's remotely from a Mac.

Post Reply