Skip to content

fivepanelhat/Blue-Moon-Portal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

72 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Blue Moon Portal: Byte Size Kai

CI RedTeam

Blue Moon Portal Banner

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.

License
Python: 3.10+
Hardware Target
NPU Acceleration
Sovereignty
CI/CD: Active
SecOps Scan
RedTeam
Dependabot
Interop
Sustainability

The 5 Ws: Project Context

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

The Problems We Are Solving

  1. Cloud Dependency & Latency: Agricultural hardware shouldn't stop working when the internet drops. We are moving inference to the edge.
  2. 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.
  3. 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.

Quick Start

Prerequisites

  • 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)

Installation & Setup

We provide separate guides for system environment setup and installation for Windows and Linux users:

Quick Start (Automated Setup)

The fastest way to install is running the cross-platform bootstrap script:

python bootstrap.py

n-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 RemoteSigned first.

Ollama Model Setup

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>

System Validation

Before running the portal in production, run the validation script to verify all components:

python validate.py

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

Running the Portal

# Start the main orchestrator
python main.py

The portal will:

  1. Connect to your MQTT broker for sensor telemetry
  2. Initialize audio/video capture streams
  3. Perform health checks on all subsystems
  4. Begin processing sensor data through Gemma 4 via Ollama
  5. Run background media pruning (auto-cleanup of old AV buffers)

Architecture Overview

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:

  1. Ingestion: Paho MQTT streams raw sensor data asynchronously; AV module buffers frame captures and audio clips.
  2. Analysis: Gemma 4 E4B-it acts as the orchestrator. It parses multi-modal input against historical logs to spot trends.
  3. 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.

Directory Structure

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

Documentation

  • 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

Technology Stack

Hardware

  • 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)

Software

  • 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)

Key Features

βœ“ 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.


Performance & Benchmarks

  • Local Inference Latency: ~0.95 seconds per query running Google's gemma4:e4b on 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.

Contributing

This project is open-source and welcomes contributions from the agritech and edge AI communities.

Getting Started as a Contributor

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Follow the development guide in DEVELOPMENT.md
  4. Submit a pull request

Code Standards

  • Type hints required (validated with mypy)
  • Docstrings for all public functions and classes
  • Black formatting (black .)
  • Unit tests with pytest

License

This project is Licensed under the Coastal Alpine Tech Limited License. See LICENSE for details.

Attribution

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.

About

"Offline multi-modal crop tracking and autonomous microgreens tracker."

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages