Posted on

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 http://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

25 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

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.