Posted on

Running SpyServer on a Raspberry Pi-3

NB: UPDATED 31st October 2017 – The following issues are fixed:

  • Typo in the auto boot script.

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

Installing SpyServer on a Raspberry Pi 3

SpyServer is now available as a Linux app that will run on the popular and cheap Raspberry Pi-3. The main benefit here is that it lets you mount the AirSpy receiver close to the antenna and then use cheap Ethernet cable for the connection back to your network. By using this technique, you can minimise feeder losses and get the receiver away from all the RF noise in the shack. At the higher VHF and UHF frequencies, the benefits can be significant. The server also allows you to access your receiver via the Internet.

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 Jessie (these instructions are based on the 10-4-17 release)
  2. Type the following in a terminal session to install the tools to build the AirSpy drivers: sudo apt-get install -y build-essential cmake libusb-1.0.0-dev pkg-config 
  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

If you are running Raspbian Jessie, you will need to upgrade GCC to v5 before SpyServer will run. Those with the Raspbian Stretch release can ignore this step as GCC-5 is included with that build.

  1. To upgrade GCC to version 5, enter the following in a terminal session: sudo nano /etc/apt/sources.list
  2. In the top line of the file that has opened, replace jessie with stretch
  3. Press control x followed by y to save and close the file.
  4. Now we can update the sources by typing: sudo apt-get update
  5. Follow this by installing gcc-5: sudo apt-get install -y gcc-5
  6. During the installation, the process will stop and show you a long list of stability warnings. This is nothing to worry about, just scroll to the end and hit q to exit the warnings and finish the installation. You will also see a warning saying that services need to be restarted. Use the tab key to select Yes and press enter to continue.
  7. When the installation completes – you need to undo the changes you made to the sources.list file.
  8. Start by typing: sudo nano /etc/apt/sources.list
  9. In the top line of the file that has opened, replace stretch with jessie
  10. Press control x followed by y to save and close the file.

That completes the installation process so just reboot and move on to the next section.

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
  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 = 20 and change value to 10 or 15. This reduces the processor load to provide capacity for multiple connections.
  8. Scroll to line: initial_gain = 5 and change to
  9. Press Control x followed by y to close and save the changes.

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

Auto-Start on Boot

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

20 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

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.