Recent Changes - Search:

Menu

editer le Menu

HABLANv2-Raspbian

HABLAN - Multispectral and Multiangular Remote Sensing of the Light at Night from High Altitude Balloon

Software package

HABLAN v2


Creative Commons Attribution-ShareAlike 4.0 International License

Introduction

The aim of this project is to develop a system capable of remotely sense multispectral and multiangular properties of light fixtures from above ground. The system is initially designed to fly on High Altitude Balloon but an application to commercial drones is also evaluated.

The linux distribution used for this system is raspbian 32-bit Release 2021-01-11, but newer distribution must be compatible.

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.

From a private network

ssh sand@servers_local_ip

Installing and configuring subsystems

Basic system installations and dependancies

  • 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 and your micro-SD card and push on "WRITE" button.
  • Connect the GPS dongle, the backup flash drive, the keyboard, the mouse and the micro HDMI cable.
  • Put the microSD card on the RPI and power it on (connect a USB-C cable with min 4 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 GMT
    sudo dpkg-reconfigure tzdata
    • Select None of the above
    • Select GMT
    • 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.
  • Create the sand account
sudo useradd sand
sudo passwd sand
sudo mkdir /home/sand
sudo cp /home/pi/.bashrc /home/sand/
sudo chown -R sand /home/sand
sudo chgrp -R sand /home/sand
sudo sh -c 'echo "sand ALL=(ALL:ALL) ALL" >> /etc/sudoers'
  • Use the raspberry configuration tool to desactivate the Auto login
sudo raspi-config
  • Select 1 System Options
  • Select S5 Boot / Auto Login
  • Select B3 Desktop GUI, requiring user to login
  • Select Finish
  • Accept to reboot the raspberry
  • Login as sand
  • Open a terminal window
  • Install the following packages
sudo apt update && sudo apt-get upgrade
sudo apt install gfortran
sudo ln -s `which gfortran` /usr/local/bin/g77
sudo apt install vim
sudo apt install vim-common
sudo apt install apache2
sudo apt install gpsd
sudo apt install gpsd-clients
sudo apt install lm-sensors
sudo apt install imagemagick
sudo apt install ntp
sudo apt install gphoto2 libgphoto2*
sudo pip3 install adafruit-circuitpython-dht
sudo apt-get install libgpiod2

SSH

SSH server allows any remote SSH client to connect to the server to remotely control system programs from the command line or to download (upstream / downstream) data.

  • We must first be sure that the SSH server start automatically when you start the computer.
sudo raspi-config
  • Select 3 Interfacing Options
    • Select P2 SSH
      • Select Yes (to enable ssh)
  • Select 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 22 -j ACCEPT
sudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
sudo iptables-save

Installing HABLAN applications

Latest available package release on github repository

  • To download HABLAN apps:
cd
mkdir git
cd git
git clone https://github.com/aubema/hablan.git
  • Copy apps to system directory:
sudo cp -f /home/sand/git/hablan/* /usr/local/bin/
sudo chmod a+x /usr/local/bin/*

Automatic startup of hablan.bash code

cd /home/sand/git/hablan
chmod a+x *
sudo cp * /usr/local/bin
sudo cp hablan.service /etc/systemd/system
sudo systemctl enable hablan.service
sudo systemctl start hablan.service

Apache server

We are using the Apache2 web server. This server allow the remote access to the data from a web interface.

To activate the web server, we must:

  • Activate userdir module
sudo a2enmod userdir
sudo service apache2 restart
  • Create the data directory and modify the permissions by doing:
sudo mkdir /var/www/html/data
sudo chmod a+rx /var/www/html/data
  • Edit the apache2 configuration file
sudo vim /etc/apache2/apache2.conf

Then type < i > to enter insert mode and add the following lines to the file

# added for HABLAN
<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
sudo a2enmod userdir
sudo service apache2 restart

USB GPS (U-blox 7)

The GPS is controlled by the gpsd server. The GPS startup may easily take 45 seconds (time to connect to available satellites). Sometime, the GPS do not succeed to connect to satellites. Most of the time this occur when satellites are masked by obstacles like mountains or buildings. To be sure that the gpsd server will work properly, do the following steps.

Edit the gpsd configuration

sudo vim /etc/default/gpsd

type < i > and set the following parameters

# Default settings for the gpsd init script and the hotplug wrapper.
# Start the gpsd daemon automatically at boot time
START_DAEMON="true"
# Use USB hotplugging to add new USB devices automatically to the daemon
USBAUTO="true"
# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group
dialout.
DEVICES="/dev/ttyACM0"
# Other options you want to pass to gpsd
GPSD_OPTIONS="-F /var/run/gpsd.sock -D 5 -N -n"

Save and quit by typing: <escape> :wq

There is a configuration transaction between the pi and the gps dongle at the beginning of the hablan.bash script. The a string is sent to the gps in order to set the mode to Airborne <1g (max altitude 50km, max horizontal and vertical velocity 100m/s). The configuration string may change from one chipset to the other. The best way to dertermine the correct string is to use the windows based application ucenter. Once determined, this string must be changed in the hablan.bash line beginning by "gpsctl".

Shutdown button

Enter the following commands in the terminal

cd /home/sand/git/hablan
chmod a+x *
sudo cp * /usr/local/bin
sudo cp shutdown_button.service /etc/systemd/system
sudo systemctl enable shutdown_button.service
sudo systemctl start shutdown_button.service

Real time clock

We are using the DS3231 RTC module to keep the date and time after powering off the system. In HABLANv2, the RTC module is included with the UPS hat.

Configure the I2C interface

sudo raspi-config

This command will bring up the configuration tool; this tool is an easy way to make a variety of changes to your Raspberry Pi’s configuration. Today, however, we will only by exploring how to enable the I2C interface.

Use the arrow keys to go down and select “3 Interfacing Options“. Once this option has been selected, you can press Enter.

  1. On the next screen, you will want to use the arrow keys to select “P5 I2C“, press Enter once highlighted to choose this option.
  2. You will now be asked if you want to enable the “ARM I2C Interface“, select Yes with your arrow keys and press Enter to proceed.
  3. Once the raspi-config tool makes the needed changes, the following text should appear on the screen: “The ARM I2C interface is enabled“.
  • Run the following command on your Raspberry Pi to install python-smbus and i2c-tools:
sudo apt-get install python-smbus i2c-tools
  • With those tools now installed run the following command on your Raspberry Pi to detect that you have correctly wired up your RTC device.
sudo i2cdetect -y 1

If you have successfully wired up your RTC circuit, you should see the ID #68 appear. This id is the address of the DS3231 RTC Chips. Once we have the Kernel driver up and running the tool will start to display UU instead, this is an indication that it is working as intended.

Setting up the Raspberry Pi RTC Time

With I2C successfully setup and verified that we could see our RTC circuit then we can begin the process of configuring the Raspberry Pi to use our RTC Chip for its time.

  1. To do this, we will first have to modify the Raspberry Pi’s boot configuration file so that the correct Kernel driver for our RTC circuit will be successfully loaded in.
  • Run the following command on your Raspberry PI to begin editing the /boot/config.txt file.
sudo vim /boot/config.txt
  • Within this file, you will want to add the following line to the bottom of the file.
dtoverlay=i2c-rtc,ds3231

Once you have added the correct line for your device to the bottom of the file you can save and quit out of it by pressing Esc, then :wq and then Enter.

With that change made we need to restart the Raspberry Pi, so it loads in the latest configuration changes.

  • Run the following command on your Raspberry Pi to restart it.
sudo reboot
  • Once your Raspberry Pi has finished restarting we can now run the following command, this is so we can make sure that the kernel drivers for the RTC Chip are loaded in.
sudo i2cdetect -y 1

You should see a wall of text appear, if UU appears instead of 68 then we have successfully loaded in the Kernel driver for our RTC circuit.

Now that we have successfully got the kernel driver activated for the RTC Chip and we know it’s communicating with the Raspberry Pi, we need to remove the fake hwclock package. This package acts as a placeholder for the real hardware clock when you don’t have one.

  • Type the following two commands into the terminal on your Raspberry Pi to remove the fake-hwclock package. We also remove hwclock from any startup scripts as we will no longer need this.
sudo apt-get -y remove fake-hwclock
sudo update-rc.d -f fake-hwclock remove

Now that we have disabled the fake-hwclock package we can proceed with getting the original hardware clock script that is included in Raspbian up and running again by commenting out a section of code.

  • Run the following command to begin editing the original RTC script.
sudo vim /lib/udev/hwclock-set

If you upgrade the operating system, you may need to redo the following step.

  • Find and comment out the following three lines by placing # in front of it as we have done below.
    • Find
    if [ -e /run/systemd/system ] ; then
    exit 0
    fi
    • Replace With
    #if [ -e /run/systemd/system ] ; then
    # exit 0
    #fi
  • Once you have made the change, save the file by pressing Esc then :wq then Enter.

Syncing time from the Pi to the RTC module

Now that we have our RTC module all hooked up and Raspbian and the Raspberry Pi configured correctly we need to synchronize the time with our RTC Module. The reason for this is that the time provided by a new RTC module will be incorrect.

  • You can read the time directly from the RTC module by running the following command if you try it now you will notice it is currently way off our current real-time.
sudo hwclock -r
  • Now before we go ahead and sync the correct time from our Raspberry Pi to our RTC module, we need to run the following command to make sure the time on the Raspberry Pi is in fact correct. If the time is not right, make sure that you are connected to a Wi-Fi or Ethernet connection.
  • If the time displayed by the date command is correct, we can go ahead and run the following command on your Raspberry Pi. This command will write the time from the Raspberry Pi to the RTC Module.
sudo hwclock -w
  • Now if you read the time directly from the RTC module again, you will notice that it has been changed to the same time as what your Raspberry Pi was set at. You should never have to rerun the previous command if you keep a battery in your RTC module.
sudo hwclock -r

You should hopefully now have a fully operational RTC module that is actively keeping your Raspberry Pi’s time correct even when it loses power or loses an internet connection.

UPS hat

The UPS is a power battery backup. It will protect the system against power fluctuations and will allow the system to continue its ongoing tasks during short power failure.

  • To enable the up, edit the file /etc/rc.local
sudo vim /etc/rc.local
  • Add a line before the exit 0 with the following content:
/usr/local/bin/ups.sh &

Configure the network parameters of the raspberry pi

Edit the file /etc/dhcpcd.conf

sudo vim /etc/dhcpcd.conf

Uncomment the section related to the static ip configurations but set ip address to 192.168.0.111

Mount the usb stick on /home/sand/backup

The usb stick will be the support to backup all the data. The backup will be done at 9 AM UT. That will be managed by the crontab.

  • Plug the usb stick in one of the RPI usb port. Type the following command:
sudo lsblk

You should see the usb drive on the sda1 drive

  • Edit fstab to mount the usb stick at /home/sand/backup
sudo umount /dev/sda1
sudo su
echo "/dev/sda1 /home/sand/backup vfat rw,user,exec,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.

crontab

The crond daemon is scheduling repetitive task on linux system. Users who have the right to use crond can schedule their own tasks to crond. We are using crond to schedule a webcam acquisition every 15 min.

Add the backup to the root crond schedule

Edit crontab

sudo su
crontab -e

chose editor 3. /usr/bin/vim.basic

type < i > and add the following content:

00 09 * * * /usr/bin/rsync -a /var/www/html/data/* /home/sand/backup

Save and quit by typing: <escape> :wq

  • Exit root account

Desactivate wifi and bluetooth

In order to avoid interference with the space agency communication systems, it is required to turn off the wifi and bluetooth services.

Edit the file /boot/config.txt

sudo vim /boot/config.txt

and add the following lines at the end of the file

dtoverlay=pi3-disable-wifi
dtoverlay=pi3-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.

Optional stuff

Edit - History - Print - Recent Changes - Search
Page last modified on December 02, 2022, at 02:59 am UTC