HABLAN - FLeYe
Software package for FLeYe v1
Creative Commons Attribution-ShareAlike 4.0 International License
Introduction
The aim of this project is to develop a system capable of remotely sense the downward hemisphere using multiple RGB cameras with variable resolution. The maximum resolution is a very high resolution of 1 meter when onboard stratospheric balloons (~30 km altitude). The cameras used are raspberry pi (RPI) HQ cams.
The linux distribution used for this system is Raspberry Pi OS (64-bit).
We chose a development philosophy based on a complete control from the Linux command line. The system can be controlled simply with a low speed remote connection provided by a SSH client installed on the user workstation. The RPI connected to the system act as a server. The images acquired by the FLeYe are stored on a web server installed on the RPI.
How to access the FLeYe
From internet:
The standard username is sand. The system administrator should be able to provide you the password for sand.
Hardware requirements
We highly suggest to chose hardware components better or equivalent to this:
- rapsberry pi 4b+ with 4 or 8 Gb of RAM
- 256 Gb microsd card U30
- 256 Gb usb3 stick
Storage
There are 27 MB of data stored on the microsd card for every shot. Which means that for each cycle of acquisition (4 images @ 2 integration times) for a given raspberry pi 27*4*2= 216 MB will be stored (8 images per cycle per RPI). On the 256 GB microsd card, there are about 222000 MB of free space. So that the microsd card can store about 1000 cycles. It takes at minimum 1.6 seconds to capture and save an image so that for the four cameras and two integration times (one cycle) it will require around 14 sec. We decided to acquire at a fixed rate. We chose 90 seconds per cycle which means 24 hours of shooting. The RPI will be in idle mode for about 40 sec after acquiring each cycle of 8 images.
Files are copied on the backup USB stick.
Integration time for night time lights detection
Assuming an analog gain of 16 (1600 ISO), the optimal integration time would be around 1/50s during night time. During day time the optimal integration time would be XXX sec. The system know the sunset and sunrise times so that it will automatically switch between the two modes.
Installing and configuring subsystems
Basic system installations and dependencies
- Download and install the Raspberry Pi Imager (https://www.raspberrypi.org/software/) (v1.4 as for this guide)
- Open the Pi Imager and choose the Raspbian OS 64 bit and your micro-SD card and push on "WRITE" button.
- Connect the backup flash usb drive in a usb 3 port (blue one), the keyboard, the mouse and the micro HDMI cable to a screen.
- Put the microSD card on the RPI and power it on (connect a USB-C cable charger with min 3 A.).
- Set your country, time zone etc to whatever you want.
- Skip the wifi config step
- Update software
- Restart the computer
- Set the correct time, time zone and date
- time zone have to be UTC
sudo dpkg-reconfigure tzdata- Select None of the above
- Select UTC
- If required, set time and date (this should be required)
sudo date -s '2017-02-03 01:35:55'- Adapt the date and time to your situation.
- Open a terminal window
- Install the following packages
sudo apt install vim-common
sudo apt install apache2
sudo apt install lm-sensors
sudo apt install ntp
sudo apt install ntpdate
sudo apt install imagemagick
sudo apt install openssh-client
sudo apt install openssh-server
sudo apt install netpbm
sudo apt install git
sudo apt install python3-serial
sudo apt install python3-dev
sudo apt install python3-rpi.gpio
sudo apt install python3-gpiozero
sudo apt install bc
sudo apt install iptables
sudo apt install gparted
sudo apt install hdate
sudo apt install wondershaper
sudo apt install gpsd
sudo apt install gpsd-clients
sudo apt install ufw
sudo apt install -y python3-kms++ python3-libcamera
sudo apt install -y python3-pyqt5 python3-prctl libatlas-base-dev ffmpeg
sudo apt install -y python3-picamera2
sudo pip install matplotlib
Installing FLeYe applications
Latest available package release on github repository
- To download FLeYe apps:
mkdir git
cd git
git clone https://github.com/aubema/FLeYe.git
- Copy apps to system directory:
sudo cp -f /home/sand/git/FLeYe/*.bash /usr/local/bin/
sudo chmod a+x /usr/local/bin/*
- Copy local configuration files
- Create the data backup directory
Mount the usb stick on /home/sand/data
The usb stick will be the support to backup all the data.
- Plug the usb stick in one of the RPI usb port. Type the following command:
You should see the usb drive on the sda1 drive
- Edit fstab to mount the usb stick at /home/sand/data
sudo su
echo "/dev/sda1 /home/sand/data vfat rw,user,exec,nofail,umask=000 0 0" >> /etc/fstab
exit
sudo reboot
Notes:
- We assume that the file system on your usb stick is FAT. Please be sure to format the usb stick accordingly before the installation.
- Be sure to replace /dev/sda1 with your actual device.
NTP -Network Time Protocole
- disable ntp service on slaves
- Add the following in /etc/ntp.conf on slaves
- Allow ntp request on the master
- Add the following in /etc/ntp.conf on master
server 127.127.1.0
fudge 127.127.1.0 stratum 10
Note: You may have to allow also ssh with ufw on the master after installing ufw.
On each RPI we will use ntpdate to sync the time at the beginning of the observe script. For the slaves we will use the IP of the master. For the master we will provide the IP of the ntp server of the gondola when onboard the CSA balloon. Otherwise, we will comment the nptdate line in observe_fleye.bash and set the time of the master manually once started using the command sudo date -s '2017-02-03 01:35:55' with the correct date. Another option is to connect a gps to the master and sync its time using that gps (see https://youtu.be/2oWLjl0dFkY).
SSH
SSH server allows any remote SSH client to connect to the server to remotely control system programs from the command line or to transfer (upstream / downstream) data.
- We must first be sure that the SSH server start automatically when the RPI boots.
- Select 3 Interface Options
- SSH
- Yes (to enable ssh)
- SSH
- ok
- Finish
- Set up your personal firewall to allow the SSH and http connections to pass through the firewall.
sudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
sudo iptables-save
Allow ssh without password from slaves
On each slave run the command
without passphrase. Then copy the .ssh/id_rsa.pub in the file .ssh/authorized_keys on the master
Limit network bandwidth
- Edit the file /etc/systemd/wondershaper.conf
Add the following to limit to 300 kbit/s
IFACE="eth0"
# Download rate in Kbps
DSPEED="300"
# Upload rate in Kbps
USPEED="300"
- Implement the automatic startup of wondershaper
- Add the following content
Description=Bandwidth shaper/Network rate limiter
After=network-online.target
Wants=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/systemd/wondershaper.conf
ExecStart=/usr/sbin/wondershaper $IFACE $DSPEED $USPEED
ExecStop=/usr/sbin/wondershaper clear $IFACE
[Install]
WantedBy=multi-user.target
- Activate Wondershaper to run persistently
Automatic startup of observation script
This is the master code that operates the image acquisition.
- observe script
chmod a+x *
sudo cp observe.service /etc/systemd/system
Adapt the content of observe.service
In the file, replace this
with
Where N is the number of the RPI you are configuring.
Automatic startup
sudo systemctl start observe.service
Schedule the watchdog to the root crond schedule
This scripts check the disk usage of the /home/sand/data directory every 5 min. If nothing new happens in 5 minutes, it will reboot the system.
- Edit crontab
crontab -e
- chose editor 2. /usr/bin/vim.basic
- type < i > and add the following content:
- Save and quit by typing: <escape> :wq
Apache server
We are using the Apache2 web server. This server allows browsing the database and look at the log file.
To activate the web server, we must:
- activate userdir module
sudo service apache2 restart
- Create the data directory and modify the permissions by doing:
sudo chmod a+rx /var/www/html/data
- Edit the apache2 configuration file
- Then type < i > to enter insert mode and add the following lines to the file
<Directory /var/www/html/data>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
- Then exit and save by typing: <escape> :wq
- Restart the webserver
Configure the network parameters of the raspberry pi
- Edit the file /etc/dhcpcd.conf
- Uncomment the section related to the static ip configurations but set ip address to 192.168.0.100 i.e.
interface eth0
static ip_address=172.20.4.160/24
static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=172.20.4.254
static domain_name_servers=172.20.4.254 8.8.8.8 fd51:42f8:caae:d92e::1
Setting server names
- Your name is either master, slave1 or slave2
- Edit the file /etc/hosts
- Add the following lines
172.20.4.161 slave1
172.20.4.162 slave2
- Note that 172.20.4.163 can be used for a laptop connecting to the FLeYe directly with an ethernet cable for debugging means.
GPS configuration
We are using the gps BN-220 that is supposed to work up to an altitude of 50 km. The TX and RX of the GPS module must be connected to the RX and TX of the RPI respectively.
- Interface options
- Serial
- Edit the gpsd configuration file
- Set the following content
GPSD_OPTIONS="-F /var/run/gpsd.sock -n"
BEFORE CSA FLIGHT: Disable wifi and bluetooth
In order to avoid interference with the Canadian Space Agency (CSA) communication systems, it is required to turn off the wifi and bluetooth services. If you are not flying with the CSA you may not need to do that step.
Edit the file /boot/config.txt
and add the following lines at the end of the file
dtoverlay=disable-bt
Save an quit by typing <escape> :wq
System reboot
Now all the relevant software are installed, in order to activate all newly added functionalities, restart the computer.