DataDrivenSailing Wiki
GitHub RepositoryContactContribuit
  • Welcome!
  • What is DDS?
  • How to use DDS?
  • How to replicate DDS?
  • How to customize DDS?
  • Who is behind DDS?
  • BoatTracker
    • Details
    • Setup Instructions
      • Hardware
      • Software
      • Enclosure
  • Hub
    • Details
    • Hub - Setup Instructions
      • Hardware
      • Software
      • Enclosure
    • Power - Setup Instructions
      • Hardware
      • Enclosure
  • BuoyTracker
    • Details
    • Setup Instructions
      • Hardware
      • Software
      • Enclosure
  • Controlbox
    • Coming soon
  • Add-ons
    • Camera
    • Coaching Buoys
  • Other
    • Core instructions
      • 3D Printing with Online Services
    • Contribuit
  • Changelog
  • Support
  • License
Powered by GitBook
On this page
  • Step by step instructions
  • A_Basic Raspberry Pi Firmware
  • Install the external wifi adapter driver
  • Create the host the network "hub"
  • Create a script that checks the network configuration and corrects it
  • B_Create a virtual environment
  • C_Copy Code from GitHub
  • D_Activate pigiod
  • E_Activate i2c
  • F_Change i2c speed
  • H_Create "Local" Service
  • I_Create "Nodered-Helper" Service
  • J_Create the docker enviroment (Mosquitto, Node-Red, Influx DB, Grafana)
  • K_Install the data explorer
  • L_SetUp InfluxDB2
  • M_Setup NodeRed
  • N_Setup Grafana
  • Optional_Add a 4G mobile router
Edit on GitHub
  1. Hub
  2. Hub - Setup Instructions

Software

Last updated 11 days ago

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:

A_Basic Raspberry Pi Firmware

  1. Install Raspberry Pi OS Lite 64bit with the with the following settings:

    1. Hostname: hub.local (replace number accordingly)

    2. Username and Password: As you like (remcommened to have the same for every device)

    3. Wlan: Use your home network

    4. Time/location: As you need

  2. Insert the SD-Card

  3. Power up the Raspberry Pi

  4. Connect via Remote Desktop ) - this extension in visual studio code cold make you life easier.

  5. Update and upgrade: sudo apt-get update && sudo apt-get -y upgrade

  6. Reboot with: sudo reboot

Install the external wifi adapter driver

It needs a driver to be installed and some configuration, so it will host your wanted network.

  1. install dependen packages packages: sudo apt install -y raspberrypi-kernel-headers build-essential bc dkms git

  2. create directory /src: mkdir -p ~/src

  3. go to the created directory: cd ~/src

  4. clone the github repository with the driver: git clone <https://github.com/morrownr/8812au-20210820.git>

  5. go to the downloaded folder: cd ~/src/8812au-20210820

  6. install the driver: sudo ./install-driver.sh

  7. 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"

  1. check the network device status: sudo nmcli device status

  2. 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

  3. turn autoconnect on for wlan0: sudo nmcli con modify "preconfigured" connection.autoconnect yes → you may have to reconnect with ssh

  4. Create a AccessPoint with the external network: sudo nmcli con add type wifi ifname wlan1 con-name hub autoconnect yes ssid hub

  5. 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
  6. Enable Internet Sharing (NAT routing) for wlan1: sudo nmcli con modify hub ipv4.method shared

  7. Start the Hotspot: sudo nmcli con up hub

  1. Restart: sudo reboot

  2. 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:

  1. create a script: sudo nano /usr/local/bin/check_wlan1.sh

  2. 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”

  3. Make it executable: sudo chmod +x /usr/local/bin/check_wlan1.sh

  4. Run it every minuite: sudo crontab -e

    1. Add this to the bottom line: * * * * * /usr/local/bin/check_wlan1.sh

  5. Reboot: sudo reboot

B_Create a virtual environment

  1. Install the python3-venv:

sudo apt install python3-venv
python3 -m venv codeenv --system-site-packages
  1. Activate the environment with: source codeenv/bin/activate

→ you should see a “(env)” in front of your Terminal name

→ for deactivate the env -> deactivate

C_Copy Code from GitHub

Since the code is divided into two parts, we need to execute similar steps for each section. 1. local code: Software that is similar to the one on the trackers and deals with the gps, anemometer, compass... 2. nodered code: Software that supports Nodered data processes. It is callable via an API. See the

  1. Install git with: sudo apt-get install git

  2. Clone the repository: git clone https://github.com/oliverheisel/DataDrivenSailing.git ddsrepo

  3. Copy the code that we need to where we need it: cp -r ddsrepo/Hub/Software/code_nodered /home/globaladmin/code_nodered

  4. Copy the code that we need to where we need it: cp -r ddsrepo/Hub/Software/code_local /home/globaladmin/code_local

  5. Remove the rest: rm -rf ddsrepo

  6. Install all required packages:

    1. Go to the folder with: cd code_local

    2. 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

  1. Open rasp-config with: sudo raspi-config

  2. Select: “Interface options” > “I2c” > “Activate i2c” _> yes

  3. Exit raspi-config

F_Change i2c speed

  1. Open the firmware configuration file with: sudo nano /boot/firmware/config.txt

  2. Search for the "dparam" line

  3. Uncomment the line by removing the hashtag

  4. Add the following, so it looks like this: → changing from 400khz to 100khz: dtparam=i2c_arm=on,i2c_arm_baudrate=100000

  5. Reboot with: sudo reboot

H_Create "Local" Service

  1. Create new service file with: sudo nano /etc/systemd/system/startmainlocal.service

  2. 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_local/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
  1. Enable service:

sudo systemctl daemon-reload
sudo systemctl enable startmainlocal.service
sudo systemctl start startmainlocal.service

I_Create "Nodered-Helper" Service

  1. Create new service file with: sudo nano /etc/systemd/system/startmainnodered.service

  2. 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
  1. Enable service:

sudo systemctl daemon-reload
sudo systemctl enable startmainnodered.service
sudo systemctl start startmainnodered.service

The service will start the main script each time the Raspberry Pi boots.

If you have to stop or restart the service (in case you changed the code) you can do it with:

STOP: sudo systemctl stop [servicename].service

RESTART: sudo systemctl restart [servicename].service

J_Create the docker enviroment (Mosquitto, Node-Red, Influx DB, Grafana)

!!! Make sure you deactivated the virtual enviroment otherwise: deactivate

  1. 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

  2. Go in the IOTStack directory: cd IOTstack/

    1. click "Build stack"

    2. 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:

    3. Everything selected → hit enter. You will end up on the start screen

    4. 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.

    5. Hit enter and than exit it.

    6. To check the running containers and check their port: docker ps

    7. To test if we can reach all service, let's check the following addresses. Make sure you are connected to the hub network:

K_Install the data explorer

  1. Open a terminal and ssh into the hub

  2. Give permissions to the folders of the IOTstack:

sudo chown -R globaladmin:globaladmin /home/globaladmin/IOTstack
sudo chmod -R 775 /home/globaladmin/IOTstack
  1. 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
  1. To check the running containers: docker ps

L_SetUp InfluxDB2

  1. Login with the default user:

    1. Username: me

    2. Password: mypassword

  2. Click on "Load data" > "Buckets"

  3. Create the following Buckets

Bucketname
Retention
Use

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

  1. Create a 3 API-Keys. "Load Data" > "API Tokens"

  2. Click "Create API-Token" > "All Access Tokens

  3. Description (1. "Grafana", 2. "NodeRed", 3. "RaspberryPi")

  4. Write all Keys down! You cant review them!

M_Setup NodeRed

  1. 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.

  2. Click the hamburger menu again, select Import, and upload the flows.json file you downloaded.

Insert API-Key

  1. Open one flow (doesn't matter wich) and find a InfluxDB node and click on it

  2. Click on the pencile next to "server"

  3. Replace the token with NodeRed you created

  4. Save and exit

N_Setup Grafana

  1. Go to "Dashboard" > "New" > "Import"

  2. Upload the file and create a new dashboard

  3. Check if the connections works - Use the InfluxDB API-Key

Congrats, you made it 🎉

Optional_Add a 4G mobile router

  1. Configure the router

    1. login to your router

    2. change to SSID: hub4G

    3. wifipassword: SailingBoat#7xTq9!

    4. Set it on auto network select + roaming on

  2. Set second wifi connection on Raspberry Pi

    1. 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
      
    2. Set connection priorities (The higher the priority value, the more preferred the network is.)

      1. sudo nmcli con modify "preconfigured" connection.autoconnect-priority 50

      2. sudo nmcli con modify "4ghotspot" connection.autoconnect-priority 30

    3. Check it:

      1. sudo nmcli connection show

      2. sudo nmcli con show "preconfigured" | grep autoconnect-priority

      3. sudo nmcli con show "4ghotspot" | grep autoconnect-priority

The needed driver for the chipset:

To not have to install everything by our self, we use IOT Stack: Here you can find the instructions: More explanation for IOT Stack and Docker you can find here:

run: ./menu.sh

Nodered:

Grafana:

InfluxDB2:

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:

Check the webui by opening the website:

Go to the InfluxDB2 WebUi:

Download the flows.json file from:

Open your browser and go to to access Node-RED.

Download the dashboard files from:

Open your browser and go to to access Grafana.

https://github.com/oliverheisel/DataDrivenSailing
Raspberry Pi Imager
https://marketplace.visualstudio.com/items?itemName=ms-vscode.remote-explorer
https://store.rokland.com/en-de/pages/alfa-awus036ach-driver-install-help-raspberry-pi-os?srsltid=AfmBOorBs4XS-8Mpf6uSAAeZ3Dq3ApVKE7zvbZ8CR53gpzx7WgxuYlPZ
https://sensorsiot.github.io/IOTstack/
https://sensorsiot.github.io/IOTstack/Basic_setup/
https://www.youtube.com/watch?v=_DO2wHI6JWQ
hub.local:1880
hub.local:3000
hub.local:8087
https://github.com/awesometic/docker-h5ai
hub.local:80
hub.local:8087
https://github.com/oliverheisel/DataDrivenSailing/tree/main/Hub/NodeRed
hub.local:1880
https://github.com/oliverheisel/DataDrivenSailing/tree/main/Hub/Grafana
hub.local:3000
Node-Red
Grafana
InfluxDB2