Posted on 58 Comments

Running SpyServer on a Raspberry Pi-3

*UPDATED 31st October 2018: A few typos corrected and instructions updated for Stretch. Also made amendments for Airspy-Mini receiver.

NB: Spy Server is undergoing active development so it’s important to regularly update both Spy Server and SDR Sharp.

Introduction

SpyServer is available as a Linux app that will run on the popular and cheap Raspberry Pi-3. This brings a number of benefits. First of all, you can mount your Airspy close to the antenna to avoid lossy cable runs whilst accessing the receiver over a network link. Due to Spy Server’s low bandwidth requirement, you can share your receiver over the wider Internet, either for your own use or to let other ops use the radio.

Installing SpyServer on a Raspberry Pi 3

Also see my ready built scripts here:

Here’s a step-by-step guide to getting SpyServer running on a Pi 3.

  1. Start with a fresh install of the latest Raspbian Stretch.
  2. Type the following in a terminal session to install the build tools and the drivers for the AirSpy receiver: sudo apt-get install -y  cmake libusb-1.0.0-dev  
  3. Now enter the following commands to download and install the AirSpy drivers:
    • wget https://github.com/airspy/host/archive/master.zip
    • unzip master.zip
    • cd airspyone_host-master
    • mkdir build
    • cd build
    • cmake ../ -DINSTALL_UDEV_RULES=ON
    • make
    • sudo make install
    • sudo ldconfig
  4. Open a web browser and navigate to http://airspy.com/download/
  5. Select the SDR Server for 32bit ARM boards and download the file.
  6. Go to the download directory by typing: cd ~/Downloads
  7. Create a new directory for SpyServer by entering the following command: mkdir ~/spyserver
  8. Extract the downloaded tgz file using the following command: tar -xvzf spyserver-arm32.tgz -C ~/spyserver
  9. Let’s check the files are in place with this command: cd ~/spyserver && ls.
  10. If all is well, you should see the files: spyserver and spyserver.config.
  11. The next task is to make SpyServer executable by entering: sudo chmod +x spyserver

That completes the installation but you need to update the SpyServer config file for your station. Here’s an example for using an AirSpy receiver with the Pi:

  1. Open a Terminal session and type: hostname -I and make a note of the IP address.
  2. Type cd ~/spyserver to make sure we’re in the right directory.
  3. Now we can open the config file by typing: sudo nano spyserver.config
  4. Scroll down to the line: device_sample_rate
  5. Amend this line to read: device_sample_rate = 2500000 (3000000 or 6000000 for Airspy Mini).*
  6. Scroll to line: #initial_frequency= 7100000 and change it to your preferred start frequency and remove the #, i.e. initial_frequency = 145000000
  7. Scroll to line: fft_fps = 15 and change value to 10. This reduces the processor load to provide capacity for multiple connections.
  8. Scroll to line: initial_gain = 5 and change to 10
  9. Press Control x followed by y then Return to close the files and save the changes.

*NB: Device Sample Rate Notes. Airspy receivers will require 2.5MSPS as the 10MSPS setting uses more USB bandwidth than the Pi can supply. However, AirSpy Mini users must use 3MSPS or 6MSPS as these are the only rates supported by that device. Reports to date indicate that 6MSPS is fine on a Pi 3B+. If you encounter any stuttering audio, you will need to drop the sample rate.

That completes the changes and your Pi is now ready to run SpyServer. You can start the server with the following command from a terminal session: cd ~/spyserver && ./spyserver

ADDING OTHER RECEIVERS

In addition to supporting the standard Airspy and Airspy Mini, Spy Server is ideal for sharing the excellent Airspy HF+ receiver. Here is the step-by-step process to install the HF+ drivers:

  1. Open a terminal session and enter: cd /home/pi
  2. Enter: wget https://github.com/airspy/airspyhf/archive/master.zip
  3. Now unzip the archive by entering: unzip master.zip
  4. Change to the new directory: cd airspyhf-master
  5. Make a new directory for the build: mkdir build
  6. Change to the new directory: cd build
  7. Make the driver with: cmake ../ -DINSTALL_UDEV_RULES=ON
  8. Complete the make with: make
  9. Move the installed files to the correct destination: sudo make install
  10. Rebuild the search path so the driver can be found: sudo ldconfig

You can also use RTL-SDR dongles with the server but you will need to add the driver as described here.

 

Auto-Start on Boot

(Note: whilst the rc.local autostart option works ok, I now recommend running the Spy Server as a service. See https://photobyte.org/raspberry-pi-running-spy-server-as-a-service/

You can also start Spy Server on boot. To do this, we need to create a dedicated /etc/rc.local script. This automatically runs at boot but will often be called before the network is ready which will cause Spy Server to fail. To overcome this I have added an ‘until’ loop that checks for the IP every second and, once detected, carries on and runs Spy Server. This IP check also has a 30 second timeout that causes the script to abandon if the IP is not available after 30 seconds. This is very crude at the moment and needs some error handling along with a message to let the user know when IP detection fails.


#!/bin/bash

# This script is executed at the end of each multiuser runlevel.

# Make sure that the script will “exit 0” on success or any other value on error.

# This script runs during boot and waits up to 30 seconds for an IP address and, if found, runs Spy Server.

counter=1
until [[ $_IP ]]
do
_IP=$(hostname -I)
sleep 1
((counter++))
if [ $counter -gt 30 ]
then
exit 1
fi
done
cd /home/pi

./spyserver spyserver.config  &

exit 0


That’s it; you should find that the server starts automatically when the Pi boots providing you have a local network.

 

Mike

58 thoughts on “Running SpyServer on a Raspberry Pi-3

  1. any posibility to run this on boot ? so you dont have to ssh intio the rpi and leave the session open ?

    1. Hi Rick,

      Yep, that’s easy. Here’s the instructions:

      1. From a terminal session, open the rc.local file by typing: sudo nano /etc/rc.local
      2. Use the cursor keys to scroll down to the line containing ‘fi’ and insert a new line above it.
      3. On the new line type: /home/pi/spyserver/./spyserver &
      4. Press Ctrl X followed by Y to save and close the file.
      Now the server will automatically start on boot 🙂

      One other point to note: I’ve discovered that by upgrading to the Stretch distribution you lose the Wi-Fi drivers. I’m sure this will be fixed but I’ll be publishing a revised process for the Pi that just gets gcc-5 from Stretch but keeps the rest of the distribution at Jessie.

      Mike – G4WNC

  2. Hi Mike
    Is a Pi zero capable of running spyserver?
    Cheers
    Richard G4FBA

    1. Hi Richard,

      Sorry, but the Pi Zero doesn’t have enough processing power for Spy Server.

      Regards,

      Mike – G4WNC

  3. Hi,

    do i have to install the Airspy Drivers when i use the RTL-SDR Reciever?

    After the installation i get the error “Unable to load user mode driver for ‘RTL-SDR’. Hope you can help me!

    Regards,

    Tim

    1. Tim, You don’t need the Airspy drivers. That error means it can’t find the rtl-sdr driver. You can check the installation by typing rtl_sdr -t.

      Regards,

      Mike ( from a very windy Le Touquet)

    2. Same problem here. rtl_eeprom and rtl_test work fine, but spyserver gives the same error:

      $ ./spyserver
      SPY Server v2.0.1590 – http://airspy.com
      Reading the configuration file: spyserver.config
      Unable to load user mode driver for ‘RTL-SDR’

      I wasn’t able to find any solution, or figure out what user-mode driver it’s trying to load.
      lsmod shows rtl2832, dvb_usb_rt128xxu and so on, so the drivers are loaded.
      I feel like spyserver wants a different driver, something from airspyone_host-master perhaps. It’s not entirely clear what that package actually does, but it compiled and installed fine.

  4. Mike, thanks for the write-up… works like a charm. Your ‘initial_gain’ recommendation is missing (Point 8 in your write-up) in the spyserver.conf section.

    Cheers
    Matt/KØMOS

  5. Is there a way to enable the direct sampling mode for RTL-SDR v3 using Spyserver? The instructions you provided were perfect for getting me up and running on 25mhz+!!! Thank you.

    1. Glad to hear the instructions worked well for you. Unfortunately, the direct sampling mode is not available at present. I also know the Airspy team are busy getting the AirspyHF+ into production at the moment so I doubt there will be much movement on RTL-SDR support in the immediate future. As and when it arrives, I’ll make a note here.

  6. Is it possible to use spyserver in gnu radio?

    1. Hi. I don’t think so. It would need someone to write a GNU radio source block to handle the protocol that’s used to package the IQ and FFT data from the Spy Server.

      Regards,

      Mike – G4WNC

      1. what a pity! I need gnu radio for “telive” (tetra decoder)

        thank you.

  7. Max or MIKE. Do you have the solution for that problem ?

    Unable to load user mode driver for ‘RTL-SDR’

    Please let me know cause I can[t find the way to solve it.

    Thanks a lot,

    ART – PY2KJ

  8. tengo este error que podra ser
    Accepted client 192.168.1.11:50151 running SDR# v1.0.0.1664 on Microsoft Windows NT 6.1.7601 Service Pack 1
    Device was sleeping. Wake up!
    Could not acquire the device
    Accepted client 192.168.1.11:50152 running SDR# v1.0.0.1664 on Microsoft Windows NT 6.1.7601 Service Pack 1
    Device was sleeping. Wake up!
    Could not acquire the device

    1. Hi Roberto,

      That error means the Spy Server software can’t see the receiver it’s expecting. This can happen if you have the wrong receiver set in the config file. If you have one of my cards, simply double-click on the desktop icon for your receiver. This will automatically alter the config file. In addition, Airspy recently made some improvements to the Spy Server code, which means that you have to update both SDR Sharp and Spy Server. If you have one of my micro SD cards, the update is easy as you just have to double-click the Update All icon on the desktop. This will automatically update the drivers for all the supported receivers, as well as Spy Server itself. You also need to update SDR Sharp on your PC to the latest version so that it will work with the new Spy Server software.

      Regards,

      Mike – G4WNC

  9. This line with the current download from this site is wrong
    http://airspy.com/download/

    Extract the downloaded tgz file using the following command: tar -xvzf spyserver-arm32.tgz -C ~/spyserver

    File name is now spyserver-arm32.gz
    not tgz

    1. Hi Neil,

      I’ve just checked the download and it is still a tgz file. Maybe it was accidentally uploaded as a gz file and then updated by the author.

  10. I too am getting the Unable to load user mode driver for RTL-SDR error.

    Looks like others have had this error, but I can’t see you have mentioned a fix for it

    The post has no mention of installing RTL-SDR drivers that I can see.

    That is the fix, follow the driver install as per your other blog
    https://photobyte.org/using-the-raspberry-pi-as-an-rtl-sdr-dongle-server/
    This is on Raspberian Stretch Lite.. all worked fine after installin ghte drivers as per the above link.

    pi@raspberrypi:~/spyserver $ ./spyserver
    SPY Server v2.0.1629 – http://airspy.com
    Reading the configuration file: spyserver.config
    Unable to load user mode driver for ‘RTL-SDR’
    Closed all connections and released the device
    *** Error in `./spyserver’: free(): invalid pointer: 0x7eb8676c ***
    Aborted
    pi@raspberrypi:~/spyserver $ rtl_sdr -t
    -bash: rtl_sdr: command not found

    1. Hi Neil and jjhgf,

      My post on installing Spy Server as a service assumed the user already had Spy Server installed and working with a manual start. I’ll add a note to that post to make it clearer.

      Thanks for the observation.
      Mike – G4WNC

      1. I think you might have misunderstood my point.
        Was not talking about the Spy Server As Service page, was talking about this very page
        Running SpyServer on a Raspberry Pi-3

        If you just follow the instructions here, above, on this page, you get the error

        pi@raspberrypi:~/spyserver $ ./spyserver
        SPY Server v2.0.1629 – http://airspy.com
        Reading the configuration file: spyserver.config
        Unable to load user mode driver

        This is before trying to start it as a Service, it will not start even manually (as above ) until the instructions on the the other page about installing
        “Using the Raspberry Pi as an RTL-SDR dongle Server” are complete.

        1. Hi Neil,
          All noted and I’ve updated the ‘Spy Server on a Pi’ post to advise users that they need to install the RTL-SDR drivers if they want to use an RTL-SDR dongle.

          Thanks,

          Mike – G4WNC

  11. I followed your directions and when I enter in the IP address and click on C in SDR# a pop up window says “Device got disconnected” and on the terminal window of the Pi I see “Device was sleeping. Wake up! and the second line says “Could not acquire the device” What have I done wrong?

    Thanks,
    Larry

    1. Hi Larry,

      Sorry for the delayed replay, busy times here! That message means Spy Server can’t see the receiver it’s expecting. On the Pi desktop you will see a number of icons for the receiver types that are supported. Each icon runs a short script that stops Spy Server, updates the server’s config file for the selected receiver and restarts the server. Check that your receiver is connected to the Pi, then double-click the appropriate icon and hit Return when it finishes. Now try SDR# again.

      Hope that does the trick!

      Regards,

      Mike – G4WNC

      1. Not a problem Mike. I found out that the response “Could not acquire the device” is caused by a bad sample rate in the “Spyserver.Config file. Once the correct sample rate is selected Spyserver is running like a finely tuned watch Mike.

        Regards,
        Larry N8NJ

  12. Hi Larry,

    I have a problem with multiple users.
    Once I have connected to spyserver, no other users can use my spyserver in a separate session. They can connect, and set a frequency, but they don’t get the audio at their set frequency, but hear the audio from my session.

    I have set the following in the config file. So it should work.

    # User sessions
    #
    maximum_clients = 5

    # Allow clients to control the device
    #
    allow_control = 5

    With kind regards, Remco

    1. Hi Remco,

      The allow control is an on/off switch for that feature, so needs be set to either 1 or 0. Where 1 allows control and 0 prevents control.

      Mike – G4WNC

  13. Hello
    how to directly connect the raspberry wifi to the wifi of a laptop (no internet router)
    That it settings on raspberry and the computer?

    thank you

    1. To connect the Pi and a laptop using WiFi, one of the devices needs to be configured as a Wi-Fi hotspot. You will find details of how to configure a Pi here: https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md
      Alternatively, you could set your laptop as a Wi-Fi hotspot. You may already have the facility to do that but you can also add software as in this example: https://www.connectify.me/blog/how-to/how-to-turn-your-windows-laptop-into-a-wifi-hotspot/

      Mike – G4WNC

  14. And in addition it works great 🙂
    Thank you so much

  15. Hi Mike;

    I have been trying to setup SpyServer on a Raspberry 3B (Dongle is a new NESDR SMArt), and followed your outstanding instructions. All seemed to go well except I keep getting an error ” kernel driver is active, or device is claimed by a second instance of librtlstr.” I have the Blacklist complete, but regardless it keeps coming back with that error.
    This comes back as “0: Realtek RTL2838UHIDIR, SN: 00000001” is the issue possibly due to the RTL chip version?

    1. Hi Jeff,

      Sorry to hear you’re having a problem. The problem clearly indicates that the blacklist is not stopping the wrong kernel module from loading. Do a detailed double-check to make sure the blacklist is correct. Maybe get someone else to check it in case you’re repeating the same mistake. one other thing to try is to add the following line to the blacklist:

      blacklist fc0013

      Let me know how you get on.

      Regards,

      Mike – G4WNC

  16. HI, thanks for your instructions. I ran into a problem, I have a headless Pi with no webbrowser so the download link points to an HTML file instead of the airspy file.

    Would you know how to get a direct link to the latest version ?

    1. Hi Ben,

      No problem, the direct link for the SpyServer update is: get http://airspy.com/downloads/spyserver-arm32.tgz

      Regards,

      Mike

  17. Mine will not find the Mini?
    Device was sleeping. Wake up!
    Could not find any suitable device

    Any recommendations?

    1. Mike,

      The device sleeping error indicates that Spy Server is running but can’t talk to the receiver. Usual causes are:

      The wrong device set in the spyserver.config file.
      or
      Receiver drivers not installed.
      or
      Firmware update needed.

      Regards,

      Mike

  18. If you have the issue I had, make sure you have latest firmware from here.
    https://github.com/airspy/airspyone_firmware/releases/tag/v1.0.0-rc10

    I connected mine to Windows, updated it and then it works!

  19. seems the spyserver works fine for a bit then the wifi drops out on the Pi – any ideas why?

    1. Hi,

      Could do with a bit more detail really but here are a few comments that may help.
      The Spy Server software is well proven and very stable so is unlikely to be the cause.
      I’ve had a Wi-Fi linked Pi3 running Spy Server here for extended periods with no problems.
      Are you using the server in reduced bandwidth mode?
      In my experience, Wi-Fi links rarely have sufficient continuous bandwidth to support the full IQ mode.
      I have found that a Wi-Fi connected Pi will drop-out if you’re trying to force too much data over the link.

      If you’re still stuck, perhaps you could supply some more details of the setup.

      Regards,

      Mike – G4WNC

  20. Mike,

    Thanks for the guide. I autostart spyserver with supervisor and edit the supervisord.conf file and add the following:

    [program:spyserver]
    command=/home/pi/spyserver/spyserver.sh
    autostart=true
    autorestart=true
    stderr_logfile=/var/log/long.err.log
    stdout_logfile=/var/log/long.out.log

    My script file looks like this:

    #!/bin/bash
    /home/pi/spyserver/spyserver /home/pi/spyserver/spyserver.config

    This keeps spyserver up and running no matter what.

    Also I’ve found I have to add airspy libairspy0 and libairspy-dev dependencies to get rolling as well.

    1. Hi John,

      Interesting. I haven’t used Supervisor so might just have to take a look.

      Ok on the Libairspy dependencies. I’d written the instructions as a bonus for anyone already using Spy Server on the Pi. I’ll update the instructions to make that clearer.

      Regards,

      Mike

  21. Hi all,

    I am running AirSpy Spyserver on an RPi 3B+ and SDR# as the client on a Windows PC. Both are connected to home WiFi network. RTL-SRD and Spyserver installations were fine, no errors, server is running. However, the audio in SDR# breaks too much, just like a buffering video. Waterfall is lagging, appears line by line in intervals. Full IQ mode is deselected. Data speed shows around 180 kbps (I don’t know if it’s bits or bytes). No Firewall, RPi is new and freshly setup without any unnecessary software. The same happens when using Gqrx as the client in Mac. Also tried increasing the buffer time, the buffer count and decreasing the frame rate, the sample rate, but nothing helps.

    Please help and thank you in advance.

    1. The broken audio is a symptom of a bandwidth limitation somewhere in the system. To prove the point, connect your Pi to your local network with an Ethernet cable. If the audio is fine, then it’s the Wi-Fi that’s causing the problem. If you have dual-band Wi-Fi, i.e. 2.4GHz and 5GHz access your router and give the 2.4GHz and 5GHz different SSIDs. You can then force the Pi to use one or the other so you can see which works the best. 5GHz is potentially faster but does penetrate walls as well as 2.4GHz. One more, often missed, point. Don’t put the Pi too close to the Wi-Fi router as this can overload the receiver front-end and increase the error rate.

      Mike – G4WNC

  22. Hi Mike,
    How do I update Spyserver ? I ran the scripts but they don’t seem to do anything.

    Also on the airspy site it doesn’t show the version of spyserver ?

    The spyserver auto start doesn’t work either, maybe some update broke something ?

    Thanks
    Mark

    1. Hi Mark,

      Do you have one of my SD Cards?

      If so, the Update All script is the only script that does an update. If all is well that will take a few minutes to complete and you should see lots of output in the terminal window that opens.
      The other scripts are only supplied so you can swap receiver hardware without manually updating the spyserver.config file.

      I’ve just been taking a close look at the latest Spy Server and the receiver swap scripts are redundant. The default spyserver.config includes a search that will start the server using whatever SDR receiver is connected.

      Mike

      1. Hi Mike,

        No I don’t have one of your sd cards.

        How do I update spyserver manually ? should I re-install everything ?

        The Spyserver starts fine when I run the script manually but what I mean is then when the Pi starts , spyserver doesn’t start automatically, that’s what I meant when I said that I think an update might have broke something.

        Thanks again.
        Mark

  23. Hello
    I can’t get spyserver run on boot. When I check status, I see:
    pi@raspberrypi:~ $ sudo service spyserver status
    ? spyserver.service – AirSpy Spyserver Service
    Loaded: loaded (/etc/systemd/system/spyserver.service; enabled; vendor preset: enabled)
    Active: failed (Result: exit-code) since Thu 2019-09-05 20:15:52 EEST; 4min 4s ago
    Process: 596 ExecStart=/home/pi/spyserver/spyserver /home/pi/spyserver/spyserver.config (code=exited, status=255/EXCEPTION)
    Main PID: 596 (code=exited, status=255/EXCEPTION)

    rugs. 05 20:15:51 raspberrypi systemd[1]: spyserver.service: Failed with result ‘exit-code’.
    rugs. 05 20:15:52 raspberrypi systemd[1]: spyserver.service: Service RestartSec=100ms expired, scheduling restart.
    rugs. 05 20:15:52 raspberrypi systemd[1]: spyserver.service: Scheduled restart job, restart counter is at 5.
    rugs. 05 20:15:52 raspberrypi systemd[1]: Stopped AirSpy Spyserver Service.
    rugs. 05 20:15:52 raspberrypi systemd[1]: spyserver.service: Start request repeated too quickly.
    rugs. 05 20:15:52 raspberrypi systemd[1]: spyserver.service: Failed with result ‘exit-code’.
    rugs. 05 20:15:52 raspberrypi systemd[1]: Failed to start AirSpy Spyserver Service.

  24. Why isn’t this published on the Airspy website?
    I’m confused why we need to follow your (otherwise perfect) tutorial to use the Airspy Mini.

  25. Hey, your directions were very helpful! I’m trying to get my Pi4 running as a public SpyServer, and whenever I boot spyserver, I get [R82XX] PLL not locked. Any chance you know how to fix that? I’ve tried going back thought all the steps and I still can’t figure it out.

    Thanks!

    1. Hi Andrew,

      That usually means Spy Server is asking the dongle to tune to a frequency that’s out of range. Go into spyserver.config and find the line:
      #initial_frequency =
      if the hash is in place, delete it and enter a number for the initial frequency that’s within the tuning range of your device. 100MHz is a safe choice, in which case the line should read:

      initial_frequency = 100000000

      Regards,

      Mike – G4WNC

  26. Hello Mike,
    i got this week a PI4 with 8GB. In past weeks i run on a PI4 4GB without any problems. Now wit 8GB PI start and on first screen some system messages and …. you using a old system …. pse update
    I return back Micro SD to the 4GB and it run’s like a rock.
    [yes, i know 8GB is not needed to run the SpyServer 🙂 ]

    73 Chris
    DL5NAM

  27. Hello, I am trying to set up RTL-SDR on HF is there a command line for this?

    1. RTL-SDR dongles will only work in HF mode (also known as direct sampling) if they have been physically modified. Some dongles, such as the RTL-SDR V3, are already modified. To use direct mode sampling with Spy Server, you need to alter the ‘spyserver.config’ file as follows:

      – Open spyserver.config
      – Scroll towards the bottom of the file looking for the line #rtl_sampling_mode
      – Remove the # from the start of the line and set the sampling mode to 1 or 2 depending on which IQ branch your dongle uses.
      – Save spyserver.config and restart the server.
      Your server will now access the RTL-SDR dongle in direct sampling mode.

      Regards,

      Mike – G4WNC

      1. Thanks Mike! Another question do the RSP/SDRPlay devices work with Airspy server?

  28. How to get airspy HF+ working on terminal only? no desktop install?
    Regards

  29. Sorry was ment to also add raspberry pi 3B+

Leave a Reply

Your email address will not be published. Required fields are marked *

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