Setting up a Raspberry Pi to run sidmon

This receiver for SID (sudden ionospheric disturbance) monitoring consists of a Raspberry Pi (RPi) board running linux and my receiver software in python. The hardware section lists the minimal items needed for the system itself. In this setup, the RPi computer is not connected to a keyboard, mouse, or monitor. Another computer (the logging computer) is instead used to log into the RPi through X11 windows and your home wireless or wired network. One talks to the RPi through terminal screens. Graphical output from the programs running on the RPi can be displayed on the logging computer via X11. The logging computer does not need to be linux. It only needs to have an X11 server and an ssh client running on it. On windows these can be xming and putty, respectively.

The hardware section describes the hardware I am using, and the setup section gives the steps to set up linux and other software on the RPi. It has taken a lot of fiddling to get the RPi up and running, and I am hoping that being specific about hardware and software these instructions might shorten the path for those of you who like myself are not particularly linux savvy.

Later sections explain how to run sidmon in the background, and to run it as a service. The latter ensures that sidmon restarts when the RPi boots, which prevents missing blocks of time after power dropouts. Finally there is info on power consumption, noise from switching power supplies, running on a battery with or without a solar panel, and remote siting.

Hardware

Minimal additional hardware is required for getting an RPi up and running over a wireless or wired network. This configuration does not use a mouse or keyboard, but is instead controlled via ssh on a linux or windows computer (use ssh on linux, or, e.g., putty on a windows computer).

Setting up the RPi

  1. Download one of the Raspbian operating system images: Get a Lite version if you do not intend to run it as a desktop. Raspbian Stretch and Jessie are dated, although they work with sidmon.
  2. Installing operating system images on an SD card. Use etcher or other application to write to the SD card. When done, unplug and then plug in the SD card.
  3. Configuring the operating system on the SD card. The important thing is to set up the RPi to connect to the network when it boots. One or two files need to be created in the boot folder of the SD card. On my laptop with the SD card plugged in, the path to the boot folder was /media/<username>/boot, where <username> is the username you are logged in as.
    1. Create an empty ssh file and place in the same folder.
      touch /media/<username>/boot/ssh
    2. For a wireless network, create the file wpa_supplicant.conf containing wireless credentials and place in the boot folder. This file is not necessary when using a wired network.
    Verify that the files are there, and be sure to they are in the right boot folder. If the folder does not have a lot of files, then it is the wrong folder. I was tripped up by both of these foibles.
  4. Unmount the SD card and plug it into the RPi. Power up the RPi. Give it a minute to boot up.
  5. Determine the IP address of the RPi. This can be done by logging into your modem and viewing the connected devices. One of them should be the Raspberry Pi. If you are not able to use this method, perhaps you can determine the address pinging IP addresses, i.e., 192.168.1.2, 192.168.1.3, etc., attempting to log in (next item).
  6. From a linux computer, log in with
    ssh -XC pi@<ipaddress>
    The password is raspberry. From a windows computer with putty installed, use:
    putty -XC pi@<ipaddress>
    The switches enable X11 port forwarding and compuression.
  7. Change the password with passwd.
  8. Optionally assign a name to the computer in the /etc/hostname file.
    sudo echo <newcomputername> > /etc/hostname
  9. Optionally create a new username with adduser.
  10. Add the user sidmon will run under to the sudo, audio, and dialout groups using usermod.
    sudo usermod -a -G sudo <username>
    sudo usermod -a -G dialout <username>
    sudo usermod -a -G audio <username>
    
  11. Optionally assign computer-name aliases for computers on your network in the /etc/hosts file.
  12. Optionally configure a static IP address for the RPi.
  13. Optionally copy the private key of your desktop or laptop to the RPI.
    ssh-copy-id <username>@<ipaddress>
  14. To install software, enter the following:
    sudo apt-get update
    sudo apt-get install -y software-properties-common
    sudo apt-add-repository -y universe
    sudo apt-get install -y git
    sudo apt-get install -y python3 python3-pip python3-dev python3-venv
    sudo apt-get install -y python3-numpy python3-matplotlib python3-scipy
    sudo apt-get install -y libasound2-dev
    sudo apt-get install -y alsa-utils
    sudp pip3 install pyalsaaudio
    sudo apt-get install -y pulseaudio
    The last may not be necessary.
  15. It is essential that alsaaudio version 0.9.0 or later is installed. Download from
    https://pypi.org/project/pyalsaaudio/#files
    to a suitable directory, such as ~/Downloads, unpack, build, and install.
    cd ~/Downloads
    tar -xf <tarfilename>
    cd <unpackeddirectory>
    python3 setup.py build
    sudo python3 setup.py install
    Test by loading in python.
    $ python3
    >>> import alsaaudio
    >>> exit()
  16. Plug in the sound card. Run arecord and check that the sound card is listed.
    arecord -L
    With an Xonar U5, among many device entries it should show
    ...
    plughw:CARD=U5,DEV=0
        ASUS XONAR U5, USB Audio
        Hardware device with all software conversions
    ...
  17. In the following I've assumed that an Asus Xonar U5 is present. To set up the sound card, run alsamixer.
    alsamixer
    1. Hit F6 and select the sound card.
    2. Hit F4.
    3. Cursor to the 'Line' column; select 'Capture' with the space bar; and cursor up to full volume.
    4. Cursor right to the 'Mic' column and deselect 'Capture' with the space bar.
    5. Cursor to 'auto gain control' and select off with the space bar or 'm' key.
    6. Hit F3.
    7. Cursor to 'PCM Capture Source' column and select 'Line' with the up and down keys.
    8. Exit with the escape key.
  18. Create a sidmon root directory somewhere to your liking. Copy the distribution file sidmon.tar.gz to this directory and unpack.
    $ tar -xf sidmon.tar.gz
    Note that python files having to do with plotting data were developed starting from the SuperSID distribution. They are modified significantly and are not interchangeable with the originals.

Configuring a static IP address

When run on a local area network (LAN) behind a modem, devices are ordinarily dynamically assigned IP addresses by the modem in the private domain, usually 192.168.1.x. A static (fixed) IP address on the LAN is a convenience in that it obviates the need to determine the RPi's IP address every time it obtains a new lease. Your modem can be configured to provide one through its configuration menus. To do this first determine your RPi's (or other sidmon host's) MAC address by entering on the sidmon host the command

ifconfig wlan0     # for wireless interface, or
ifconfig eth0      # for ethernet interface, or
ifconfig -a        # for all interfaces
One of the interfaces will be the wireless or wired interface you are using. Note the MAC address of the form hh:hh:hh:hh:hh:hh associated with that interface, where 'h' refers to a hexadecimal character. Log into your modem and navigate to the page used to assign static DHCP addresses. On my ZyXEL DSL modem it is under Network Settings -> Static DHCP. Add a new entry and enter the MAC address you noted. Then choose a new static address in the DHCP address range configured for the modem and enter that address in its place on that configuration page. Make sure that that IP address does not conflict with a device currently on your network.

Running the program in the background

When running from a terminal, logging off or other disruption of the terminal session will kill sidmon. To avoid this problem, it is convenient to run sidmon in the backgound without connection to a terminal. Running without a terminal session is simple with nohup.

nohup src/sidmon.py <options> &
When run this way the user can log off without stopping the program. The sidmon -lp switch should not be specified so that no live plot is generated. Make a note of the process ID so that the process can be stopped with the kill command later. Alternatively, the process ID can be learned later using the ps command. The process by the name python is likely the correct one.
ps -U pi
  PID TTY          TIME CMD
  428 ?        00:00:00 systemd
  431 ?        00:00:00 (sd-pam)
 1363 ?        1-10:36:32 python
 4059 ?        00:00:00 sshd
 4062 pts/0    00:00:01 bash
 4169 pts/0    00:00:00 ps

Note in the earlier command that the path to the python interpreter might be different than shown on other machines.

Installing sidmon as a service

Power glitches and dropouts naturally disrupt sidmon. When the power comes back the computer will boot, but sidmon will not restart itself. To keep the data flowing it is necessary to have sidmon automatically restart on power up, and without a terminal session. It is possible to have the program run at startup by entering commands in /etc/rc.local, but installing as a service is nearly as easy. Instructions for a template towards this end are at this link. In summary
  1. Download the template, copy it to /etc/init.d, and give it a meaningful name, such as sidmon. Edit the file
    vi /etc/init.d/sidmon
    and after Provides: in the file enter that name.
    ...
    Provides: sidmon
    ...
  2. Enter the directory the program starts in, the command that starts the program, and the user name the program runs under in the dir, cmd, and user lines. An example is
    ...
    dir="/home/<username>/<path>"
    cmd="src/sidmon.py -t 4.5"
    user="<username>"
    ...
    where <username> is the user name under which sidmon will be run, and <path> is the relative path to the sidmon root directory. There are also places to change the files to which stdout, stderr are redirected, and a file for the process ID. You might wish to enter locations for those files more convenient than the defaults in the template.
  3. Make the script executable and owned by root
    sudo chmod +x /etc/init.d/sidmon
    sudo chown root:root /etc/init.d/sidmon
  4. To have it run automatically at boot time, enter
    sudo update-rc.d sidmon defaults
    sudo update-rc.d sidmon enable
  5. To manage sidmon, It is helpful to define an alias in .bashrc or elsewhere
    alias sidmon='/etc/init.d/sidmon'
    There are four commands. Manually start the program as a service with
    sidmon start
    check the status using
    sidmon status
    restart the service (stop then restart) with
    sidmon restart
    and stop the service with
    sidmon stop

Other notes

Links