This guide details how to set up a Raspberry Pi as a remote camera client for the MultiPi system. It covers OS installation, network configuration, and the MultiPi client software setup. In the folder raspberry-pi-setup you can find all the files needed to setup the Raspberry Pi.
In the raspberry-pi-setup/3d_files directory within the repository, you can find all the 3D models for a case to hold the Raspberry Pi 4 and camera module 3 as well as a mounting bracket to mount the case easily. See the 3D Files README for previews and printing details.
We recommend using the official Raspberry Pi Imager to flash your SD card.
- OS Choice: Use a recent version of Raspberry Pi OS (e.g., Bookworm). Choose the "Lite" version if you don't need a graphical desktop.
- Imager Settings: Use the Imager's advanced options to:
- Set a hostname for the Pi.
- Enable SSH.
- Set a username and password.
- Configure WiFi credentials (works for standard WPA2 networks).
Ensure your Raspberry Pi can connect to the network where the MultiPi server and MQTT broker reside.
If you didn't configure WiFi using the Imager, or need to change it, you can use the nmtui tool (NetworkManager Text User Interface) after connecting via SSH (see next section).
sudo nmtuiNavigate to "Activate a connection" to connect to available networks or "Edit a connection" to add/modify settings.
For more complex networks (like university or company WiFi):
-
Connect the Pi temporarily using an Ethernet cable or a simpler WiFi network.
-
SSH into the Pi (see next section).
-
Create or edit a connection file in
/etc/NetworkManager/system-connections/. Give it a descriptive name (e.g.,my-enterprise-wifi-name.nmconnection). -
Populate the file with your network's specific settings. Below is a generic template (replace placeholders):
[connection] id=my-enterprise-wifi-name uuid=924f17a3-105d-4370-ad0f-661f0d5d9915 # Generate one using `uuidgen` type=wifi autoconnect=true autoconnect-priority=10 # Higher number means higher priority [wifi] mode=infrastructure ssid=Your_Enterprise_SSID [wifi-security] key-mgmt=wpa-eap [802-1x] eap=PEAP; identity=your_username@your_domain.com password=your_password # Optional settings - check requirements for your network: # anonymous-identity=anonymous@your_domain.com # ca-cert=/path/to/your/ca/certificate.pem # phase2-auth=mschapv2 # subject-match=CN=your_radius_server.your_domain.com [ipv4] method=auto [ipv6] addr-gen-mode=stable-privacy method=auto
-
Set correct permissions:
sudo chmod 600 /etc/NetworkManager/system-connections/my-enterprise-wifi.nmconnection
-
Restart NetworkManager:
sudo systemctl restart NetworkManager
Consider adding a secondary, lower-priority connection (e.g., to a phone hotspot) to maintain access if the primary network configuration changes:
- Create another
.nmconnectionfile (e.g.,phone-hotspot.nmconnection). - Set
autoconnect-priority=0(lower than your primary connection). - Configure the hotspot's SSID and password.
sudo systemctl status NetworkManager
journalctl -u NetworkManager # View logs
nmcli device wifi list # List available networks
nmcli connection show # List configured connectionsWiFi Configuration (Pre-Bookworm / wpa_supplicant - Deprecated)
For older Raspbian versions using wpa_supplicant, create a wpa_supplicant.conf file on the boot partition of the SD card before first boot.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CH # Set your country code
network={
ssid="Your_Enterprise_SSID"
key_mgmt=WPA-EAP
eap=PEAP
identity="your_username@your_domain.com"
password="your_password" # Or use hash: see below
# Optional:
# anonymous_identity="anonymous@your_domain.com"
# phase2="auth=MSCHAPV2"
# ca_cert="/path/to/ca.pem"
# subject_match="CN=your_radius_server.your_domain.com"
priority=10
}For additional security, the password can be stored as a hash. To generate the hash, you can use the raspberry-pi-setup/hash_password.sh script.
You can find more information about WiFi settings at this link.
Once the Pi is booted and connected to the network, connect from your computer:
ssh your_pi_username@your_pi_hostname.local
# Or use the IP address if .local resolution fails
# ssh your_pi_username@<pi_ip_address>For passwordless access (recommended for scripting/fleet management):
- Generate Key Pair (on your computer):
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_rpi # Choose a filename
- Copy Public Key to Pi:
ssh-copy-id -i ~/.ssh/id_rsa_rpi.pub your_pi_username@your_pi_hostname.local - Connect:
ssh -i ~/.ssh/id_rsa_rpi your_pi_username@your_pi_hostname.local
Log in to the Pi via SSH and perform initial updates and install required system packages:
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y python3 python3-pip python3-venv ffmpeg gitNow, install the MultiPi client application.
-
Clone the Repository:
git clone https://github.com/M-Eng/multipi.git cd multipi -
Create Virtual Environment (Recommended):
python3 -m venv venv source venv/bin/activateNote: If using the systemd service later, ensure the service file points to the python executable inside this
venv. -
Install Python Dependencies:
# Ensure you are in the multipi directory and venv is active pip install -r src/client/requirements.txt
Configure the client to connect to your server and MQTT broker.
- Navigate to the configuration directory:
cd configs/ - Copy the example configuration:
cp config_client.example.ini config_client.ini - Edit
config_client.iniusing a text editor (e.g.,nano config_client.ini). Set:- MQTT broker address, port, and certificate paths (if using TLS).
- Server address for video streaming.
- Any RPi-specific camera settings.
- Return to the project root:
cd ..
Accurate time is crucial for MultiPi. Raspberry Pi OS uses systemd-timesyncd. You can optionally increase polling frequency for potentially better sync:
- Edit the configuration:
sudo nano /etc/systemd/timesyncd.conf
- Uncomment and adjust
PollIntervalMinSecandPollIntervalMaxSec(values between 32-64s are reasonable). You can also specify custom NTP servers if needed.[Time] #NTP= #FallbackNTP= ... RootDistanceMaxSec=5 PollIntervalMinSec=32 PollIntervalMaxSec=64
- Restart the service:
sudo systemctl restart systemd-timesyncd
- Check status:
timedatectl status
The MultiPi client offers three primary modes of operation, corresponding to different main scripts in src/client/:
-
main.py(Standard Remote Control):- This is the standard client mode for remote control via the central server.
- Connects to the MQTT broker and listens for commands (start/stop recording, get picture, ping, shutdown, reboot).
- Requires the server and MQTT broker to be running.
- Uses
configs/config_client.iniby default.
-
main_auto.py(Scheduled Recording):- Runs independently and records video locally based on time windows defined in its configuration file (
configs/config_client_auto.iniby default). - Still connects to MQTT for status reporting and remote commands like PING, GET_PICTURE, SHUTDOWN, REBOOT (but ignores START/STOP commands).
- Crucially requires the Pi to have accurate time. Ensure the clock is synchronized at boot (e.g., via NTP, requires internet access - see Section 7) or use an external Real-Time Clock (RTC) module.
- Runs independently and records video locally based on time windows defined in its configuration file (
-
main_manual.py(Manual Button Control):- Specifically for Raspberry Pi setups with a physical button and LED connected to GPIO pins (see script for default pins: Button=GPIO27, LED=GPIO17).
- Pressing the button starts/stops local recording.
- Holding the button triggers a shutdown.
- Does not connect to MQTT or the server.
- Uses
configs/config_client_manual.iniby default.
Ensure you are in the multipi directory and the virtual environment is activated (source venv/bin/activate). Choose the script corresponding to the desired mode:
- Standard Remote Control:
python3 src/client/main.py --config configs/config_client.ini
- Scheduled Recording:
# Make sure clock is synchronized! python3 src/client/main_auto.py --config configs/config_client_auto.ini - Manual Button Control:
# Requires button/LED connected to GPIO python3 src/client/main_manual.py --config configs/config_client_manual.ini
Use the provided systemd service file for automatic startup. This is typically used for the Standard Remote Control (main.py) or Scheduled Recording (main_auto.py) modes.
-
Locate and Edit Service File: The file is likely at
src/client/systemd-service/multipi-client.service(verify this path).# Example path - VERIFY! SERVICE_FILE="$HOME/multipi/src/client/systemd-service/multipi-client.service" nano "${SERVICE_FILE}"
Crucially, edit the file to set:
User: The username the Pi runs as (e.g.,pi).WorkingDirectory: The absolute path to themultipidirectory (e.g.,/home/pi/multipi).ExecStart: The absolute path to thepython3executable within the virtual environment and the correct script (main.pyormain_auto.py) with its corresponding config file (--config ...).- Example
ExecStartfor standard mode:ExecStart=/home/pi/multipi/venv/bin/python3 /home/pi/multipi/src/client/main.py --config /home/pi/multipi/configs/config_client.ini - Example
ExecStartfor auto mode:ExecStart=/home/pi/multipi/venv/bin/python3 /home/pi/multipi/src/client/main_auto.py --config /home/pi/multipi/configs/config_client_auto.ini - Example
ExecStartfor manual mode:ExecStart=/home/pi/multipi/venv/bin/python3 /home/pi/multipi/src/client/main_manual.py --config /home/pi/multipi/configs/config_client_manual.ini
- Example
-
Copy, Enable, and Start:
sudo cp "${SERVICE_FILE}" /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable multipi-client.service sudo systemctl start multipi-client.service
-
Check Status/Logs:
sudo systemctl status multipi-client.service sudo journalctl -f -u multipi-client.service # Follow logs
Once one Pi is fully configured, you can clone its SD card for others using rpi-clone. Install it following instructions from its GitHub repository.
- Insert the target SD card into a USB reader connected to the configured Pi.
- Identify the target SD card device name:
lsblk
- Clone and assign a new hostname:
# Replace sdX with the target device (e.g., sda) and new_hostname sudo rpi-clone sdX -f -U # -f non interactive, -U update uuid # Mount the boot partition of the new SD card (e.g. /dev/sda1) # Change the hostname in /etc/hostname on the new SD card
The script raspberry-pi-setup/update_rpi_remote.sh can be used to update multiple Pis listed in a file.
- Create a file (e.g.,
pi_list.txt) with one hostname or IP per line. - Ensure you have passwordless SSH configured to all target Pis.
- Run the script:
# Assuming script is in scripts/ directory ./scripts/update_rpi_remote.sh pi_list.txt