🐟 PTAGIS M5 Builder #
Build and manage Raspberry Pi environments for PTAGIS M5 fish monitoring software.
PTAGIS (PIT Tag Information System) tracks tagged fish across the Columbia River Basin. The M5 Monitor Service runs on Raspberry Pis at field sites, reading PIT tag detections from interrogation systems and reporting them upstream.
This tool lets you:
- Develop and test M5 configurations in a Docker container (no Pi hardware needed)
- Build flashable SD card images ready for field deployment
- Manage site configurations through a friendly CLI or interactive TUI
Requirements #
- Python 3.11+
- uv (Python package manager)
- Podman (preferred) or Docker
- On macOS:
brew install podman && podman machine init && podman machine start - On Linux:
sudo apt install podman(ordnf install podman) - Docker also works as a fallback — the tool auto-detects which is available
- On macOS:
That's it. Everything else runs inside containers.
Installation #
Requires uv (fast Python package manager).
# Clone the repository
git clone <repo-url>
cd ptagis
# Install everything (creates .venv, installs deps + dev tools)
uv sync
Verify it works:
uv run ptagis --help
To run tests:
uv run pytest
Quick Start #
Three commands to get M5 running locally:
# 1. Set up your site (answers 3 questions)
ptagis init
# 2. Build the container
ptagis build
# 3. Start M5
ptagis run
M5 Monitor Service is now listening on port 5440. Configure it using the M5 Control Panel (Windows desktop app connects via SignalR).
Commands #
ptagis init #
Interactive setup wizard. Asks for:
- Site name — a hostname for your Pi (e.g.,
rpi-m5-site1) - Static IP — the IP address the Pi will use (default:
192.168.1.24/24) - Gateway — your network gateway (default:
192.168.1.1)
Creates a .env configuration file with sensible defaults for everything else.
ptagis build #
Builds the Docker container with your configuration. This creates an arm64 Debian Trixie environment with M5 installed and configured — mirroring the services that run on a real Pi.
ptagis build # Uses .env in current directory
ptagis build --env .env.site2 # Use a different config file
ptagis run #
Starts the container. M5 Monitor Service launches automatically on port 5440.
ptagis run
# M5 Monitor listening on port 5440 (SignalR for M5 Control Panel)
ptagis shell #
Opens a bash shell inside the running container for debugging or manual inspection.
ptagis shell
# You're now inside the Pi environment
# journalctl -u m5 -f # Watch M5 logs
# systemctl status m5 # Check M5 status
# exit # Return to host
ptagis test #
Runs validation checks against the running container:
- M5 service is active
- Port 5440 is listening
- Hostname matches config
- SSH is running
- Architecture is arm64
ptagis test
ptagis logs #
Stream M5 Monitor service logs from the running container.
ptagis logs # Follow m5monitor logs (Ctrl+C to stop)
ptagis logs --no-follow # Show recent logs and exit
ptagis logs -s pit-emulator # Follow emulator service logs
ptagis scan #
Activate the PIT tag emulator and display detected tags in real-time.
ptagis scan # Scan for 10 seconds (default)
ptagis scan --duration 30 # Scan for 30 seconds
ptagis status #
Show container and service status at a glance.
ptagis status
ptagis image #
Builds a flashable SD card image by customizing the official Raspberry Pi OS Lite. Takes ~3 minutes (after base image is cached).
ptagis image
# Output: output/ptagis-m5.img.xz
Flash the image to an SD card:
# Using dd (Linux/macOS)
xz -dc output/ptagis-m5.img.xz | sudo dd of=/dev/sdX bs=4M status=progress
# Or use Raspberry Pi Imager (any OS):
# Choose "Use custom" and select the .img.xz file
Requirements: podman (macOS) or sudo + losetup (Linux), plus xz.
ptagis doctor #
Checks that your system is ready to build:
- Podman/Docker installed and running
- QEMU registered (for x86 hosts building arm64 images)
- Sufficient disk space
- Network connectivity
- Valid .env configuration
ptagis doctor
If something fails, follow the fix suggestions in the output.
ptagis config show #
Displays your current configuration in a table.
ptagis config show
ptagis config edit #
Opens the interactive TUI configuration editor with inline validation.
ptagis config edit
ptagis tui #
Launches the full interactive TUI with all operations accessible via keyboard shortcuts:
| Key | Action |
|---|---|
| B | Build container |
| R | Run container |
| S | Open shell |
| T | Run tests |
| I | Build image |
| C | Edit config |
| D | Run doctor |
| ? | Show help |
| Q | Quit |
Managing Multiple Sites #
Each site gets its own .env file:
# Set up a second site
cp .env .env.site2
# Edit .env.site2 with different hostname/IP
# Build for that site
ptagis build --env .env.site2
Configuration Reference #
All settings in .env:
| Variable | Default | Description |
|---|---|---|
PI_HOSTNAME |
rpi-m5-site1 |
Pi hostname |
PI_STATIC_IP |
192.168.1.24/24 |
Static IP with CIDR |
PI_GATEWAY |
192.168.1.1 |
Network gateway |
PI_DNS |
8.8.8.8 |
DNS server |
PI_INTERFACE |
eth0 |
Network interface |
M5_VERSION |
2.2.9 |
M5 software version |
M5_SOURCE |
(empty) | URL (https://...) or local path (packages/m5.deb) |
M5_ARCH |
arm64 |
arm64 or armhf |
SSH_PUBKEY_PATH |
~/.ssh/id_ed25519.pub |
SSH public key to install |
PI_LOCALE |
en_US.UTF-8 |
System locale |
PI_TIMEZONE |
UTC |
Timezone |
PI_KEYBOARD_LAYOUT |
us |
Keyboard layout |
INSTALL_WATCHDOG |
true |
Install watchdog service |
INSTALL_UNATTENDED_UPGRADES |
true |
Install auto-updates |
INSTALL_MOSQUITTO_CLIENTS |
true |
Install MQTT clients |
INSTALL_EMULATOR |
true |
Install PIT tag emulator (dev/test only) |
PI_GEN_IMAGE_NAME |
ptagis-m5 |
Output image filename |
Using a Local M5 Package #
If you can't download M5 at build time (air-gapped environment, unstable network):
Option A — Local file:
- Download the
.debfrom https://www.ptagis.org/Software/M5/M5 - Place it in the
packages/directory - Set in
.env:M5_SOURCE=packages/m5_2.2.9_arm64.deb
Option B — URL (downloaded at build time):
M5_SOURCE=https://your-server.com/m5_2.2.9_arm64.deb
Then build as normal: ptagis build
Troubleshooting #
"Neither podman nor docker found" #
Install podman:
- macOS:
brew install podman && podman machine init && podman machine start - Linux:
sudo apt install podman(Debian/Ubuntu) orsudo dnf install podman(Fedora)
"QEMU binfmt not registered" #
On x86 Linux, run:
podman run --privileged --rm tonistiigi/binfmt --install arm64
On macOS, podman machine handles this automatically.
Build is slow on x86 #
ARM emulation via QEMU adds overhead on x86 hosts. First builds take longer; subsequent builds use layer caching. On Apple Silicon Macs, arm64 runs natively.
M5 service not starting in container #
The M5 service is installed but requires site configuration to start. In the dev container,
the PIT tag emulator provides a virtual serial port (/dev/ttyEMU0) so M5 has hardware to
talk to. To check the emulator status: ptagis shell then systemctl status pit-emulator.
See docs/emulator.md for details.
M5 download fails #
If the M5 URL is unreachable:
- Download the
.debmanually from https://www.ptagis.org/Software/M5/M5 - Place in
packages/ - Set
M5_SOURCE=packages/m5_2.2.9_arm64.debin.env
Container won't start #
ptagis doctor # Check prerequisites
podman compose logs # View container logs
Project Structure #
ptagis/
├── .env.example # Config template — copy to .env
├── pyproject.toml # Python project definition
├── src/ptagis_builder/ # Source code
├── emulator/ # PIT tag transceiver emulator (Rust)
├── templates/ # Jinja2 templates for Docker/compose/NetworkManager
├── config/ # Static config files (SSH, systemd)
├── packages/ # Local .deb files (optional)
├── output/ # Built SD card images (generated, gitignored)
├── .cache/ # Downloaded base images (gitignored)
├── tests/ # Test suite
└── docs/ # Documentation