Software
Step by step instructions
You don't have to program the compute module yourself, but you have to set it up. The following steps help you to setup your Tracker.
If you want to have a deeper insight in the code itself, you can find the documented code in the github repository: https://github.com/oliverheisel/DataDrivenSailing
A_Basic Raspberry Pi Firmware
Install Raspberry Pi OS Lite 64bit with the Raspberry Pi Imager with the following settings:
Hostname: hub.local (replace number accordingly)
Username and Password: As you like (remcommened to have the same for every device)
Wlan: Use your home network
Time/location: As you need
Insert the SD-Card
Power up the Raspberry Pi
Connect via Remote Desktop https://marketplace.visualstudio.com/items?itemName=ms-vscode.remote-explorer) - this extension in visual studio code cold make you life easier.
Update and upgrade:
sudo apt-get update && sudo apt-get -y upgrade
Reboot with:
sudo reboot
Install the external wifi adapter driver
The needed driver for the chipset: https://store.rokland.com/en-de/pages/alfa-awus036ach-driver-install-help-raspberry-pi-os?srsltid=AfmBOorBs4XS-8Mpf6uSAAeZ3Dq3ApVKE7zvbZ8CR53gpzx7WgxuYlPZ
It needs a driver to be installed and some configuration, so it will host your wanted network.
install dependen packages packages:
sudo apt install -y raspberrypi-kernel-headers build-essential bc dkms git
create directory /src:
mkdir -p ~/src
go to the created directory:
cd ~/src
clone the github repository with the driver:
git clone <https://github.com/morrownr/8812au-20210820.git
>go to the downloaded folder:
cd ~/src/8812au-20210820
install the driver:
sudo ./install-driver.sh
reboot:
sudo reboot
→ The led on the wifi module should start flashing
If not → ip a
→ If it not shows wlan1 → check if adapter is listed in lsusb
→ Bus 001 Device 003: ID 0bda:8812 Realtek Semiconductor Corp. RTL8812AU 802.11a/b/g/n/ac 2T2R DB WLAN Adapter
If the modul doesnt start flashing after rebooting, run the installation of the driver again.
Create the host the network "hub"
check the network device status:
sudo nmcli device status
if wlan1 connection is “preconfigured” → that means the external wifi adapter. The external wifi adapter is needed for the website hosting. Before disconnecting wlan1 we want to connect wlan0 to the home network. Otherwise our connection to the Pi
Connect wlan0 to the preconfigured/ home network:
sudo nmcli con up "preconfigured" ifname wlan0
turn autoconnect on for wlan0:
sudo nmcli con modify "preconfigured" connection.autoconnect yes
→ you may have to reconnect with sshCreate a AccessPoint with the external network:
sudo nmcli con add type wifi ifname wlan1 con-name hub autoconnect yes ssid hub
Add the AP configuration (change the password and channel accordingly)
sudo nmcli con modify hub 802-11-wireless.mode ap sudo nmcli con modify hub 802-11-wireless.band bg sudo nmcli con modify hub 802-11-wireless.channel 6 sudo nmcli con modify hub wifi-sec.key-mgmt wpa-psk sudo nmcli con modify hub wifi-sec.psk "SailingBoat#7xTq9!" sudo nmcli con modify hub 802-11-wireless-security.proto rsn sudo nmcli con modify hub 802-11-wireless-security.pairwise ccmp sudo nmcli con modify hub 802-11-wireless-security.group ccmp sudo nmcli con modify hub connection.autoconnect yes sudo nmcli con modify hub connection.autoconnect-priority 100
Enable Internet Sharing (NAT routing) for wlan1:
sudo nmcli con modify hub ipv4.method shared
Start the Hotspot:
sudo nmcli con up hub

Restart:
sudo reboot
Check if everything works:
sudo nmcli device status
Create a script that checks the network configuration and corrects it
Add a small script, to ensure, that wlan1 stays with hosting the hub network:
create a script:
sudo nano /usr/local/bin/check_wlan1.sh
paste this:
#!/bin/bash # Ensure wlan1 is always in AP mode if ! nmcli -t -f DEVICE,STATE device | grep -q "wlan1:connected"; then echo "wlan1 is down! Restarting AP..." nmcli con up hub fi # Ensure wlan0 is connected to either home WiFi or backup WiFi if ! nmcli -t -f DEVICE,STATE device | grep -q "wlan0:connected"; then echo "wlan0 is down! Trying home WiFi..." nmcli con up "preconfigured" ifname wlan0 || { echo "Home WiFi not available, trying backup WiFi..." nmcli con up "4ghotspot" ifname wlan0 } fi
“STRG” + “X” → “Y” → “Enter”
Make it executable:
sudo chmod +x /usr/local/bin/check_wlan1.sh
Run it every minuite:
sudo crontab -e
Add this to the bottom line:
* * * * * /usr/local/bin/check_wlan1.sh
Reboot:
sudo reboot
B_Create a virtual environment
Install the python3-venv:
sudo apt install python3-venv
python3 -m venv codeenv --system-site-packages
Activate the environment with:
source codeenv/bin/activate
C_Copy Code from GitHub
Install git with:
sudo apt-get install git
Clone the repository:
git clone https://github.com/oliverheisel/DataDrivenSailing.git ddsrepo
Copy the code that we need to where we need it:
cp -r ddsrepo/Hub/Software/code_nodered /home/globaladmin/code_nodered
Copy the code that we need to where we need it:
cp -r ddsrepo/Hub/Software/code /home/globaladmin/code
Remove the rest:
rm -rf ddsrepo
Install all required packages:
Go to the folder with:
cd code_local
Install the packages:
pip install -r requirements.txt
D_Activate pigiod
pigpiod itself is a daemon that provides low-level access to Raspberry Pi’s GPIO pins. Paste the following code in the terminal:
sudo systemctl enable pigpiod
sudo systemctl start pigpiod
E_Activate i2c
Open rasp-config with:
sudo raspi-config
Select: “Interface options” > “I2c” > “Activate i2c” _> yes
Exit raspi-config
F_Change i2c speed
Open the firmware configuration file with:
sudo nano /boot/firmware/config.txt
Search for the "dparam" line
Uncomment the line by removing the hashtag
Add the following, so it looks like this: → changing from 400khz to 100khz:
dtparam=i2c_arm=on,i2c_arm_baudrate=100000
Reboot with:
sudo reboot
H_Create "Local" Service
Create new service file with:
sudo nano /etc/systemd/system/startmainlocal.service
Paste the following in the file and exit it with "Ctrl"+"X" > "Y" > "Enter"
[Unit]
Description=Run Main.py on Boot local
After=network.target
[Service]
User=globaladmin
WorkingDirectory=/home/globaladmin/code_local
ExecStart=/bin/bash -c 'source /home/globaladmin/codeenv/bin/activate && /home/globaladmin/codeenv/bin/python /home/globaladmin/code/main.py'
Restart=always
RestartSec=2
Environment=VIRTUAL_ENV=/home/globaladmin/codeenv
Environment=PATH=/home/globaladmin/codeenv/bin:$PATH
ExecStartPre=/bin/sleep 5
[Install]
WantedBy=multi-user.target
Enable service:
sudo systemctl daemon-reload
sudo systemctl enable startmainlocal.service
sudo systemctl start startmainlocal.service
I_Create "Nodered-Helper" Service
Create new service file with:
sudo nano /etc/systemd/system/startmainnodered.service
Paste the following in the file and exit it with "Ctrl"+"X" > "Y" > "Enter"
[Unit]
Description=Run Main.py on Boot
After=network.target
[Service]
User=globaladmin
WorkingDirectory=/home/globaladmin/code_nodered
ExecStart=/bin/bash -c 'source /home/globaladmin/codeenv/bin/activate && /home/globaladmin/codeenv/bin/python /home/globaladmin/code_nodered/main.py'
Restart=always
RestartSec=2
Environment=VIRTUAL_ENV=/home/globaladmin/codeenv
Environment=PATH=/home/globaladmin/codeenv/bin:$PATH
ExecStartPre=/bin/sleep 5
[Install]
WantedBy=multi-user.target
Enable service:
sudo systemctl daemon-reload
sudo systemctl enable startmainnodered.service
sudo systemctl start startmainnodered.service
J_Create the docker enviroment (Mosquitto, Node-Red, Influx DB, Grafana)
To not have to install everything by our self, we use IOT Stack: https://sensorsiot.github.io/IOTstack/ Here you can find the instructions: https://sensorsiot.github.io/IOTstack/Basic_setup/ More explanation for IOT Stack and Docker you can find here: https://www.youtube.com/watch?v=_DO2wHI6JWQ
Download and install IOTstack:
curl -fsSL https://raw.githubusercontent.com/SensorsIot/IOTstack/master/install.sh | bash
→ this can take a while. It also depends on the strength of your Raspberry Pi. It will install Docker and other requirements for us! → it will restart in this process. Don’t worry. Just connect via SSH again
Go in the IOTStack directory:
cd IOTstack/
run:
./menu.sh
click "Build stack"
Select with the following containers to build with the spacebar and arrow keys: (mosquitto, nodered, influxdb2, grafana) !! When you select nodered, it will show an issue. Just open the options for node red (hitting right arrow) and select “Select & build add ons list. → hit enter and next step just go with the default selection and hit enter again:
Everything selected → hit enter. You will end up on the start screen
Now lets start the stack: Go to “Docker commands” and select “Start stack” → It will start pulling the images for the containers - this can take a while.
Hit enter and than exit it.
To check the running containers and check their port:
docker ps
To test if we can reach all service, let's check the following addresses. Make sure you are connected to the hub network:
Nodered: hub.local:1880
Grafana: hub.local:3000
InfluxDB2: hub.local:8087



K_Install the data explorer
To be able do download the data that we collected, to drag it into the analytic software, you need another container. Information about the image: https://github.com/awesometic/docker-h5ai
Open a terminal and ssh into the hub
Give permissions to the folders of the IOTstack:
sudo chown -R globaladmin:globaladmin /home/globaladmin/IOTstack
sudo chmod -R 775 /home/globaladmin/IOTstack
Paste this to get the data explorer image "h5ai" and run it as docker container
docker run -d \
--name fileexplorer \
--restart unless-stopped \
-p 80:80 \
-v /home/globaladmin/IOTstack/volumes/nodered/data/dataexport:/h5ai \
-v /config/dir:/config \
-e PUID=$(id -u) \
-e PGID=$(id -g) \
awesometic/h5ai
To check the running containers:
docker ps
Check the webui by opening the website: hub.local:80
L_SetUp InfluxDB2
Go to the InfluxDB2 WebUi: hub.local:8087
Login with the default user:
Username: me
Password: mypassword
Click on "Load data" > "Buckets"
Create the following Buckets
BoatLog
12 hr
Temporary log of live boat data
BoatStatus
12 hr
Temporary log of boat status
BuoyLog
12 hr
Temporary log of live buoy data
Comments
7 days
Database of comments and marks for timeline
HubLog
7 days
Database for all sensors on the hub
Create a 3 API-Keys. "Load Data" > "API Tokens"
Click "Create API-Token" > "All Access Tokens
Description (1. "Grafana", 2. "NodeRed", 3. "RaspberryPi")
Write all Keys down! You cant review them!
M_Setup NodeRed
Download the flows.json file from: https://github.com/oliverheisel/DataDrivenSailing/tree/main/Hub/NodeRed
Open your browser and go to hub.local:1880 to access Node-RED.
In Node-RED, click the hamburger menu in the top-right corner, select Manage Palette, go to the Install tab, search for node-red-node-ui-table, and click Install.
Click the hamburger menu again, select Import, and upload the flows.json file you downloaded.
Insert API-Key
Open one flow (doesn't matter wich) and find a InfluxDB node and click on it
Click on the pencile next to "server"
Replace the token with NodeRed you created
Save and exit
N_Setup Grafana
Download the dashboard files from: https://github.com/oliverheisel/DataDrivenSailing/tree/main/Hub/Grafana
Open your browser and go to hub.local:3000 to access Grafana.
Go to "Dashboard" > "New" > "Import"
Upload the file and create a new dashboard
Check if the connections works - Use the InfluxDB API-Key
Congrats, you made it 🎉
Optional_Add a 4G mobile router
Configure the router
login to your router
change to SSID: hub4G
wifipassword: SailingBoat#7xTq9!
Set it on auto network select + roaming on
Set second wifi connection on Raspberry Pi
ssh into the hub and paste the following into the terminal:
sudo nmcli con add type wifi ifname wlan0 con-name "4ghotspot" ssid "hub4G" sudo nmcli con modify "4ghotspot" wifi-sec.key-mgmt wpa-psk sudo nmcli con modify "4ghotspot" wifi-sec.psk "SailingBoat#7xTq9!" sudo nmcli con modify "4ghotspot" connection.autoconnect yes
Set connection priorities (The higher the priority value, the more preferred the network is.)
sudo nmcli con modify "preconfigured" connection.autoconnect-priority 50
sudo nmcli con modify "4ghotspot" connection.autoconnect-priority 30
Check it:
sudo nmcli connection show
sudo nmcli con show "preconfigured" | grep autoconnect-priority
sudo nmcli con show "4ghotspot" | grep autoconnect-priority
Last updated