Welcome to the Blue Moon Portalβthe central nervous system for the Byte Size Kai initiative. This repository houses the architecture for an autonomous, on-premise agritech crop tracker designed to optimize microgreen cultivation through edge-based AI.
- Who: Built by Coastal Alpine Tech Limited, supporting the Horowhenua Mana Kai Project.
- What: A multi-modal, agentic IoT pipeline that ingests sensor telemetry, audio, and visual data to autonomously manage and predict crop yields.
- Where: Deployed on-site in Horowhenua, New Zealand (Engineered at HQ in New Plymouth, Taranaki).
- When: Active development. We are building the sovereign digital infrastructure of tomorrow, today.
- Why: To establish localized data sovereignty. Relying on cloud compute for real-time agricultural decisions introduces latency and creates dependencies. We are bringing the brain directly to the soil.
- Cloud Dependency & Latency: Agricultural hardware shouldn't stop working when the internet drops. We are moving inference to the edge.
- Unstructured IoT Data: Sensors generate massive amounts of noise. We are solving the problem of parsing raw floats and integers into structured, deterministic JSON for automated actions.
- Fragmented Context: Traditional setups look at water levels or camera feeds in isolation. We are building a multi-modal agent that contextualizes soil moisture alongside visual leaf health and ambient acoustic data.
- Raspberry Pi 5 (16GB RAM) with Raspberry Pi AI HAT+ (Hailo-8 NPU)
- ESP32 microcontrollers for sensor integration
- Python 3.10+
- Ollama (local LLM runtime)
- Gemma 4 E4B-it model (via
ollama pull gemma4:e4b)
We provide separate guides for system environment setup and installation for Windows and Linux users:
- Prerequisites & System Setup Guide: Read setup.md
- Installation Guide: Read installation.md
The fastest way to install is running the cross-platform bootstrap script:
python bootstrap.pyn-portal python bootstrap.py
### Manual Installation (Bare Metal + Virtual Environment)
<details open>
<summary><strong>π§ Linux / macOS (Bash)</strong></summary>
```bash
# Clone the repository
git clone https://github.com/fivepanelhat/blue-moon-portal.git
cd blue-moon-portal
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Copy environment template and configure
cp .env.example .env
# Edit .env with your settings (MQTT broker, Ollama host, etc.)
πͺ Windows (PowerShell)
# Clone the repository
git clone https://github.com/fivepanelhat/blue-moon-portal.git
cd blue-moon-portal
# Create virtual environment
python -m venv venv
.\venv\Scripts\Activate.ps1
# Install dependencies
pip install -r requirements.txt
# Copy environment template and configure
Copy-Item .env.example .env
# Edit .env with your settings (MQTT broker, Ollama host, etc.)Note: If you receive an execution policy error, run
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedfirst.
Before running the portal, ensure Ollama is running and the Gemma 4 model is downloaded:
# Terminal 1: Start Ollama server
ollama serve
# Terminal 2: Pull the Gemma 4 model
ollama pull gemma4:e4b
# Verify installation
ollama list
# Expected output: gemma4:e4b c6eb396dbd59 9.6 GB <timestamp>Before running the portal in production, run the validation script to verify all components:
python validate.pyThis will test:
- β Configuration loading from
.env - β Ollama connectivity and model availability
- β MQTT broker connectivity
- β Audio/Video capture streams
- β Hardware control simulation
- β Media pruner functionality
- β AI Agent methods and LLM integration
Expected output (6-7/7 tests pass):
β PASS: configuration
β PASS: ollama
β PASS: mqtt (or β FAIL if broker not running)
β PASS: av_capture
β PASS: hardware_control
β PASS: media_pruner
β PASS: ai_agent_methods
Note: MQTT test may fail if no broker is running locallyβthis is expected in development. The portal will attempt reconnection at runtime.
# Start the main orchestrator
python main.pyThe portal will:
- Connect to your MQTT broker for sensor telemetry
- Initialize audio/video capture streams
- Perform health checks on all subsystems
- Begin processing sensor data through Gemma 4 via Ollama
- Run background media pruning (auto-cleanup of old AV buffers)
This is not a simple chatbot hooked up to a water pumpβit's a fully agentic architecture:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β EDGE HARDWARE (RPi 5 + AI HAT+) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββ ββββββββββββββββ βββββββββββββ β
β β MQTT Sensors β β CSI Camera β β Microphoneβ β
β β (Capacitive β β (Leaf Health)β β (Anomaly) β β
β β Moisture, β β β β Detection β β
β β Light, RH) β β β β β β
β ββββββββ¬ββββββββ ββββββββ¬ββββββββ βββββββ¬ββββββ β
β β β β β
β βββββββββββββββββββΌββββββββββββββββββ β
β βΌ β
β βββββββββββββββββββββββ β
β β AI Agent (Gemma β β
β β 4 E4B via Ollama) β β
β β [Multi-modal LLM] β β
β ββββββββββ¬βββββββββββββ β
β β β
β βββββββββββββββββΌββββββββββββββββ β
β βΌ βΌ βΌ β
β ββββββββββ ββββββββββ ββββββββββ β
β β Pump β β Light β βAlerts β β
β βControl β β Controlβ βSystem β β
β ββββββββββ ββββββββββ ββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Media Pruner: Auto-cleanup & Compression β β
β β (Prevents 24/7 capture from saturating SD) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Data Flow:
- Ingestion: Paho MQTT streams raw sensor data asynchronously; AV module buffers frame captures and audio clips.
- Analysis: Gemma 4 E4B-it acts as the orchestrator. It parses multi-modal input against historical logs to spot trends.
- Action & Prediction: Model generates live optimization scripts. Anomalies trigger local hardware (pumps, lights); predictions feed real-time crop yield and logistics info to the user.
Blue_Moon_Portal/
β
βββ portal_core/ # The Engine Room
β βββ __init__.py
β βββ ai_agent.py # Multi-modal LLM controller (Gemma 4 via Ollama)
β βββ mqtt_client.py # Paho MQTT subscriber for ESP32 telemetry
β βββ av_capture.py # OpenCV/PyAudio streams (CSI camera + mic)
β βββ media_pruner.py # Storage lifecycle management (auto-delete/compress)
β
βββ portal_schemas/ # The Rulebook (Pydantic enforcement)
β βββ __init__.py
β βββ ai_models.py # Pydantic classes (SensorReading, AnalysisResult, CropOptimizationPlan)
β
βββ telemetry_data/ # Local Knowledge Base
β βββ sensor_logs/ # Historical MQTT JSON payloads
β βββ media/ # Image and audio buffer storage
β
βββ requirements.txt # Python dependencies
βββ requirements-dev.txt # Development tools (pytest, black, mypy)
βββ main.py # Asynchronous event loop orchestrator
βββ setup.py # Package configuration
βββ .env.example # Environment variable template
βββ .gitignore # Git exclusions (media, .env, __pycache__)
βββ blue-moon.service # Systemd service for auto-start on boot
β
βββ README.md # This file
βββ ARCHITECTURE.md # Detailed technical breakdown
βββ HARDWARE_SETUP.md # RPi5 + Hailo-10H NPU assembly & driver installation
βββ DEVELOPMENT.md # Local dev setup, mocking, testing
- ARCHITECTURE.md β Data flow, module responsibilities, Gemma 4 config, Pydantic schema definitions
- HARDWARE_SETUP.md β RPi 5 + Hailo-10H NPU assembly, ESP32 wiring, Ollama installation, critical NPU driver setup
- DEVELOPMENT.md β Local dev environment, mock MQTT payloads, testing strategies
- Compute: Raspberry Pi 5 (16GB RAM)
- Acceleration: Raspberry Pi AI HAT+ (Hailo-8 NPU, 26 TOPS)
- Sensors: ESP32 microcontrollers streaming via MQTT
- Cameras: CSI camera module (leaf health)
- Audio: USB microphone (anomaly detection)
- Language: Python 3.10+
- LLM Runtime: Ollama (local, no cloud)
- Model: Gemma 4 E4B (4B effective parameters, multi-modal)
- Message Queue: Paho MQTT
- Schema Enforcement: Pydantic (prevents LLM hallucinations)
- Media Capture: OpenCV + PyAudio
- Process Management: Systemd (auto-start on boot)
β Edge-Native: All inference runs locally on RPi 5. No cloud dependency.
β Multi-Modal AI: Simultaneously processes sensor telemetry, visual, and audio data.
β Deterministic Output: Pydantic schemas prevent conversational hallucinations; LLM must output valid JSON or fail loudly.
β Auto-Recovery: Systemd service ensures portal restarts after power loss.
β Storage-Aware: Automated media pruning prevents 24/7 AV capture from filling the SD card.
β Open Source: Full transparency for agricultural data sovereignty.
- Local Inference Latency: ~0.95 seconds per query running Google's
gemma4:e4bon Raspberry Pi 5. - Energy Consumption: Peak active NPU execution draw is ~1.5W, enabling solar-powered off-grid deployment.
- Storage Footprint: media pruner limits raw camera frame buffer size below 500MB, retaining compliance records for 7+ years in compressed format.
This project is open-source and welcomes contributions from the agritech and edge AI communities.
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Follow the development guide in DEVELOPMENT.md
- Submit a pull request
- Type hints required (validated with
mypy) - Docstrings for all public functions and classes
- Black formatting (
black .) - Unit tests with
pytest
This project is Licensed under the Coastal Alpine Tech Limited License. See LICENSE for details.
Built by: Wayne Roberts, Coastal Alpine Tech Limited
Supporting: Horowhenua Mana Kai Project
Location: New Plymouth, Taranaki / Horowhenua, New Zealand
Date: Active development (as of May 31, 2026)
Reference:
Running Gemma 4 E4B Locally β Hardware constraints and edge configuration walkthrough.
Questions? Open an issue or reach out to the Coastal Alpine Tech Limited team.
