Details : SBC¶
Cursor (an AI assistant) was used throughout this log as a research and writing aid — to explain technical concepts, summarise reference material, clarify questions, and help structure and draft the documentation. All explanations were reviewed, tested against the actual build where possible, and verified by the author.
Week 1¶
-
Week 2¶
-
Week 3¶
-
Week 4¶
-
Week 5¶
-
Week 6¶
-
Week 7¶
-
Week 8¶
-
Week 9¶
-
Week 10¶
-
Week 11 : Raspberry Pi set up to publish MQTT commands through LoRA¶
The Raspberry Pi 4 acts as the central server and controller for the project. MQTT messages are transmitted through a LoRa bridge to the remote device that should trigger the load-switching mechanism. The wireless link itself was first prototyped in Week 11 : Networking & Communications.
Several lessons learned on it during the experiment is documented below.
Basics of Raspberry Pi¶
- The Raspberry Pi is a small, low-cost single-board computer : a full computer on one board that runs a Linux operating system, with USB ports, networking (Wi-Fi / Ethernet), and a row of GPIO pins for talking to hardware. Unlike a microcontroller (the XIAO ESP32-C3), it runs a real OS and can host services like a database, a web/API server, or an MQTT broker.
- Hardware setup :
- Appropriate power supply
- A microSD card and a microSD card reader (to flash it from computer)
- Optional, only if not doing a "headless" setup : an HDMI display, a USB keyboard and a mouse for the first boot
- Installation method (only project-specific procedures are outlined, anything else please refer to available online resources)
- Install Raspberry Pi imager on the laptop
- Insert microSD card via the reader and open Imager
- enable SSH for remote access, choose username and password, and WiFi name + password
- Write the card
The first boot takes a while and could last 45 minutes.
- Remote access :
- From the user's laptop terminal, connect with username and the Pi's hostname or IP address.
- When entering the password, the characters typically not displayed. Once the password has been entered, press Enter to continue.
- On success the prompt should show
fabacademy@raspberrypi:~ $
Knowing the Pi's current IP address is important, particularly when hostname resolution is unavailable or the device is connected to a different network.
-
Setting up fixed IP address :
- By default the router assigns IP addresses automatically, which hands each device a dynamic IP — an address leased for a limited time that can change when the lease expires, or when the device reconnects or the router reboots. Therefore, it is better to set a fixed/static IP so that the server is reachable all the time including over the user's SSH.
-
On the Pi using NetworkManager, first list the connections to find the WiFi profile name
-
Set the fix address
Experiment specific setup¶
The Python scripts is to be executed on the Raspberry Pi. The procedure for running it is outlined below :
-
System update and Python setup :
-
Update package lists and installed software
-
Create isolated Python environment for the project and activate
-
Install project dependencies
-
Enable the serial (UART) port for the LoRA through
Go to Interface Options → Serial Port, disable the login shell over serial, and enable the serial port hardware, then reboot.
-
-
Transferring Python files from laptop to Pi
Alternatively an entire directory can be copied recursively using the -r option
-
Cd to the project folder. Run the environment. Run the python script.
Observations and next iteration¶
The experiment achieved its intended objectives. However, several issues and opportunities for improvement were identified during testing and have been documented for consideration in the next design iteration.
-
Pi becomes unreachable after being left idle for a while. Hypothesis is that the Wi-Fi power saving feature is enables and so it needs to be disabled with
-
Manual log in and start the python script by hand everytime.
-
Create a service file :
-
Copy the code into it (see the admonition below)
-
Reload systemd, enable it (so it starts on every boot), and start it :
-
Service file — mqtt-lora-bridge.service
The script automatically runs at boot and automatically restarts it (after 5 seconds) if it ever crashes.
[Unit]
Description=MQTT to LoRa bridge server
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=fabacademy
WorkingDirectory=/home/fabacademy/myproject
ExecStart=/home/fabacademy/server-env/bin/python /home/fabacademy/myproject/mqtt_lora_bridge.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Week 12-13¶
-
Week 14¶
-
Week 15¶
-
Week 16¶
-
Week 17¶
-
Week 18¶
-
Week 19¶
-
Week 20¶
-