Pi4 with Raspbian Bullseye

From Global Meteor Network
Revision as of 11:04, 20 January 2023 by Lancer (talk | contribs)
Jump to navigation Jump to search

Work in progress

Introduction

The Raspberry Pi is excellent in the role of RMS station. It has just enough processing power with proper external connections. The task of RMS station can be combined with other tasks, as long as they are not too heavy. Possible examples:

  • ADSB receiver
  • NTP server

Pi4 cpu usage.png

Memory usage, on average, stays below 1GB so any model would suffice. If your have more memory you could do without a swap partition. This is especially useful if the station uses a flash card as storage. The RMS station task causes a lot of read/write actions. The best way would be to add an external USB3 disk. Any disk would do. External power for the disk should not be necessary, as long as relatively small SSD disks are used.

Pi4 memory usage.png

If you decide to add an SSD disk to the Raspberry, see these instructions to boot from SSD by default. [1]

The easiest way to run an RMS station is by using the standard RMS image. If you want to have more control, because the Pi will be doing other things as well, or want to have more control over versions used you can build your own. With the latest version of Raspbian, this is not a hard task. You can start by flashing either the default or the lite version of Raspbian Bullseye to your flash card or USB disk.

This howto assumes you are logged into the Pi with SSH (secure shell). You can also connect monitor and keyboard or use VNC to connect to the Raspberry (enable VNC using raspi-config).

Connecting to the network

There are several option to setup networking connections. The best way would be to connect the camera and the Raspberry to a switch. If you have no wired network available you could connect the camera to the Raspberry directy and then connect the Raspberry to the main network over Wifi.

If you want to connect the camera to your Pi directly

If you want to do this you have to setup a DHCP service on the Raspberry. You can find the proper way to configure the camera in the manual to build one. Make sure to use and address range different from your main network. (Note: These instructions were copied over from the original manual)

1. First, install the DHCP server:

 sudo apt-get install -y isc-dhcp-server

2. Edit the DHCP configuration file:

 sudo nano /etc/dhcp/dhcpd.conf

We need to add a fixed address for the camera, so append this at the end of the file:

 subnet 192.168.42.0 netmask 255.255.255.0 {
   authoritative;
   pool {
 	  range 192.168.42.10 192.168.42.10;
   }
   option broadcast-address 192.168.42.255;
   default-lease-time 600;
   max-lease-time 7200;
   option domain-name "local";
 }

This will assign a fixed IP address 192.168.42.10 to the camera.

3. Edit the DCHP server configuration so it will only listen to the ethernet interface. Open the file:

 sudo nano /etc/default/isc-dhcp-server

and edit the line with INTERFACESv4 by adding "eth0":

 INTERFACESv4="eth0"

4. Next, we need to give the ethernet interface the proper subnet. Open:

 sudo nano /etc/dhcpcd.conf

and add this at the end of the file:

 interface eth0
 static ip_address=192.168.42.1/24

This will give the ethernet interface a static IP address.

5. Finally, the DHCP server will try to run before the ethernet interface is up, which will produce an error. We can tell it to try again, until it is successful. Run the following commands:

 sudo cp /run/systemd/generator.late/isc-dhcp-server.service /etc/systemd/system
 sudo nano /etc/systemd/system/isc-dhcp-server.service

Edit the [Service] section:

  • set Restart=on-failure
  • add RestartSec=5 to instruct systemd to wait 5 seconds before restarting a failed service.

Add the [Install] section which is missing, and add the follow line to it:

 WantedBy=multi-user.target

Run the commands:

 sudo systemctl daemon-reload
 sudo systemctl disable isc-dhcp-server
 sudo systemctl enable isc-dhcp-server

6. Reboot so to test the configuration:

 sudo reboot

Make sure the camera is connected to the Pi’s ethernet interface, and that a fixed IP address of 192.168.42.10 is set on the camera.

7. Now, if you run arp -a, you will be able to see the IP camera: ? (192.168.42.10) at 00:12:16:b6:79:db [ether] on eth0 If not, check the status of the DHCP server service:

 sudo service isc-dhcp-server status

The service should be active.

Preparation of the Raspberry Pi to run RMS

If the Raspberry is already running. Check if your filesystem is using the full disk. To do this log in to the Pi and run the command:

 df -h

The size of /dev/root should be near your disk size. If it is not, you still need to expand the filesystem. Use raspi-config for this task.

 sudo raspi-config

- Choose “Advanced Options” (6) and then “Expand Filesystem” (A1)

While you are in raspi-config also set GPU memory to 256

- Choose “Performance options” (4) and then “GPU Memory” (P2)

And set the timezone to UTC

- Choose “Localisation options” (5) and then “None of the above” and then “UTC”

Save your settings and exit raspi-config without rebooting the Pi

If your Raspberry has 2GB of memory or less, you can enable swap by editing (sudo nano /etc/dphys-swapfile) the file /etc/dphys-swapfile and set

 CONF_SWAPSIZE=1024

Save the file and do:

 service dphys-swapfile restart

Reboot the pi

 sudo shutdown -r now


Create user accounts

After reboot, login as user pi and create an account to run RMS and an account for yourself. You could also use the pi account, but using non-default usernames is a best (security) practise.

 sudo useradd -m [your name] -g pi -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,render,netdev,spi,i2c,gpio,lpadmin
 sudo passwd [yourname]
 sudo echo [yourname] ALL=(ALL) NOPASSWD: ALL
 sudo useradd -m rms
 sudo passwd -l rms

Now you have an account on your name equal to the pi account and a locked rms account. we don’t need interactive logon for rms so blocking it is a wise thing to do.

Now log out of the Pi and login under your own account. Then do:

 sudo passwd -l pi

By default the /tmp directory is used for temporary file storage. This directory is located in the working memory of the Pi and not on disk. As such, there is not enough space available in this directory to do the installation. So we need to use another location.

Become user rms and use another directory for temporary file storage:

 sudo su - rms
 mkdir tmp
 echo export TMP=/home/rms/tmp >> .profile
 echo export TEMP=/home/rms/tmp >> .profile
 exit

Install packages

Before installing any new packages lets first make sure all current software is up to date

 sudo apt-get update
 sudo apt-get upgrade -y

The first command updates the copy of the package list and the second upgrades any outdated packages (The -y options means you wont have to confirm the upgrade). It is a wise thing to do this at least on a weekly basis.

Next install additional packages which are needed by RMS. This command will install even mopre packages that you specify. This is because some packages depend on others. And some packages won't be installed, because they are already present.

 sudo apt-get install -y cmake git mplayer python3 python3-dev python3-tk python3-pip libblas-dev libatlas-base-dev liblapack-dev at-spi2-core libopencv-dev python-imaging-tk libffi-dev libssl-dev socat ntp libxml2-dev libxslt-dev imagemagick ffmpeg qt5-qmake python3-pyqt5 libqt5gstreamer python3-pyqt5.qtmultimedia qtgstreamer-plugins-qt5 libqt5gstreamer-dev libqt5gstreamerui libqt5gstreamerutils g++ g++-10 gcc-10 gcc-10-base gcc-7-base gcc-8-base gcc-9-base gfortran gfortran-10 gstreamer1.0* libgstreamer-opencv1.0-0 python3-opencv python3-opencv-apps  ros-opencv-apps opencv-data opencv-doc libopencv* python3-setuptools python3-scipy cython3 cython3-dbg python3-pytest-cython python3-astropy* python3-paramiko python3-matplotlib* libcfitsio9 libwcs7 python3-pyqtgraph python3-git python3-pil git git-man wxpython-tools wx3.0-headers wx-common python3-wxgtk4.0 libwxgtk3.0-gtk3-dev libwxgtk3.0-gtk3-0v5 libwxbase3.0-dev libwxbase3.0-0v5 screen

Finally, install the Python virtual environment tool with:

 sudo pip3 install virtualenv

Some of the later tasks also require a Rust compiler. This is not available in the Raspbian package repository and needs to be installed by hand in the rms account.

 sudo su - rms
 curl https://sh.rustup.rs -sSf | sh

And proceed with installation. Verify correct installation with:

 sudo -i -u rms rustc --version

While you are here download the RMS software as well:

 mkdir Desktop (might already exist)
 mkdir source
 cd source
 git clone https://github.com/CroatianMeteorNetwork/RMS.git

and exit the rms account:

 exit

Finally, install the Python virtual environment tool with:

 sudo pip3 install virtualenv

Create the virtual Python environment for RMS

Become the user rms (you can exit the user rms with the command exit)

 sudo su - rms

Create the virtual environment:

 virtualenv vRMS

Activate the virtual environment:

 source ~/vRMS/bin/activate

And activate it on re-login:

 echo source ~/vRMS/bin/activate >> ~/.bashrc
 echo cd ~/source/RMS >> ~/.bashrc

Now install the nescessary Python modules. This takes a while:

 pip3 install -U pip setuptools
 pip3 install Pillow
 pip3 install gitpython cython pyephem astropy paramiko
 pip3 install matplotlib
 pip3 install imreg_dft
 pip3 install configparser==4.0.2
 pip3 install numpy==1.23.5
 pip3 install imageio==2.6.1
 pip3 install scipy==1.6.0
 pip3 install pyfits
 pip3 install pyqtgraph
 pip3 install pyqt5 --config-settings --confirm-license= --verbose

And exit the rms account:

 exit

Setting up RMS

Become the user rms with:

 sudo su - rms

Configure git so that the script can stash changes in the repo and update the code:

 git config --global user.email "rms@gmn.uwo.ca"
 git config --global user.name "RMS"

Ready the RMS software with (you should already be in the directory /source/RMS):

 python setup.py install
 ./Scripts/GenerateDesktopLinks.sh

Now find your coordinates on the globe. Your location needs to be known very accurately (to 5 decimal places). Use GPS for this or an accurate map. Put this information in the .config file in the RMS directory.

 nano .config

Also, change the configuration of the camera.

Now run RMS for the first time.

 ./Scripts/RMS_FirstRun.sh

If you have no station-ID yet. Request one with the instructions shown on screen and then abort the script by pressing the Ctrl-C key combination. Start again when you have your Station-ID in your config file.

When RMS runs successfully, stop RMS. In the next chapter a script will be created to automatically start and update RMS and restart RMS when it is not running for some reason.

Exit the rms account

Create startscripts to run RMS

Create a script to (re-)start RMS automatically. Create a new script file by doing:

 sudo nano /usr/local/bin/RMS.sh

and put the following contents in it and save:

 #!/usr/bin/bash
 MYHOME=/home/rms
 RESTART=/tmp/RESTART_RMS
 STARTAT=/tmp/START_RMS
 # Set environment variables
 export HOME=${MYHOME}
 export PATH=${MYHOME}/vRMS/bin:${MYHOME}/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
 source ${MYHOME}/vRMS/bin/activate
 # Check if FirstRun is running and start if not
 ps -ef | grep -v grep | grep RMS_FirstRun.sh >/dev/null 2>&1
 if [ $? -eq 0 ]
 then
   # Check if restart token is set
   if [ -f ${RESTART} ]
   then
     # Nicely kill FirstRun first
     FRPID=`ps -ef | grep -v grep | grep -vi screen | grep RMS_FirstRun.sh | head -n1 | tr -s ' ' | cut -f 2 -d ' '`
     kill -11 $FRPID
     echo $FRPID > ${STARTAT}
     rm ${RESTART}
     # Will be restarted at the next run
   fi
 else
   date > ${STARTAT}
   screen -d -m ${MYHOME}/source/RMS/Scripts/RMS_FirstRun.sh
   if [ -f ${RESTART} ]
   then
     rm ${RESTART}
   fi
 fi