Skip to content

WilliamMajanja/AgriPulse-EdgeCluster

Repository files navigation

AgriPulse FMIS

License Stars Forks Issues PRs Welcome Last Commit Repo Size

A Farm Management Information System with sovereign edge computing β€” built for a 3-node Raspberry Pi 5 cluster with Hailo-10H AI acceleration, real-time sensor telemetry, and on-device LLM-powered agronomy.

AgriPulse runs entirely on edge hardware: no cloud dependencies, no data leaving the farm. A FastAPI backend orchestrates sensor sampling, actuator control, and AI inference via a local Ollama model, while a lightweight HTML/CSS/JS frontend delivers a responsive dashboard accessible from any browser on the LAN.

Python FastAPI SQLAlchemy Ollama SQLite Docker Kubernetes Raspberry Pi


Table of Contents


Highlights

Feature Description
Edge Edge-native architecture 3-node Raspberry Pi 5 cluster with a Hailo-10H NPU (26 TOPS) for on-device vision inference.
Realtime Real-time telemetry WebSocket streaming of sensor data (temperature, humidity, soil moisture, NPK, pH) at 2.5 s intervals.
AI AI Agronomist Chat with a local Llama 3.1 model via Ollama for crop planning, troubleshooting, and task tool-calling.
AI AI Farm Onboarding Describe your farm in plain language; the AI streams its reasoning, extracts a structured template (fields, crop cycles, tasks), and creates it in one transaction.
Domain Full FMIS domain model Farms, fields, crop cycles, soil & plant-health readings, irrigation, fertilization, harvests, and tasks.
Control Actuator control Pump, misters, lights, fans, and fertilizer lines, exposed via WebSocket tool calls.
DevOps Deployment-ready Docker Compose and Kubernetes (Kustomize) manifests included.

Tech Stack

Backend

Python FastAPI SQLAlchemy Pydantic Uvicorn HTTPX

AI / LLM

Ollama Llama 3.1

Frontend

HTML5 CSS JavaScript

Database

SQLite PostgreSQL

Deployment

Docker Kubernetes

Edge Hardware

Raspberry Pi 5 Hailo-10H

The frontend ships as vanilla HTML/CSS/JS with no build step and no framework, and real-time communication flows over a single WebSocket (/ws) for telemetry, chat, onboarding, and tool calls.


Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Frontend (HTML / CSS / JS)                  β”‚
β”‚  Dashboard Β· Fields Β· Soil Β· Plants Β· Tasks Β· Irrigation     β”‚
β”‚  Chat Β· BOM Β· Setup (AI Onboarding)                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚ REST + WebSocket
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                FastAPI Backend (Python)                      β”‚
β”‚  Routes Β· WebSocket Manager Β· Sensor Manager                 β”‚
β”‚  SQLAlchemy ORM Β· Ollama Service Β· Onboarding Service        β”‚
β”‚  Actuator Control                                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚                               β”‚
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β”‚  SQLite /      β”‚            β”‚   Ollama (LLM)    β”‚
      β”‚  PostgreSQL    β”‚            β”‚   llama3.1:8b     β”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β”‚  Edge Hardware (Raspberry Pi 5 cluster)         β”‚
      β”‚  Sensors Β· Actuators Β· Hailo NPU Β· Camera       β”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

Prerequisites

  • Python 3.12+
  • Ollama running locally with a pulled model (ollama pull llama3.1:8b) β€” optional; the app falls back to a deterministic parser if Ollama is unreachable.
  • pip, and optionally Docker / kubectl for containerized deployment.

Option A β€” Run locally (simulated sensors)

# 1. Install dependencies
pip install -r backend/requirements.txt

# 2. (Optional) Start Ollama and pull the model
ollama serve &
ollama pull llama3.1:8b

# 3. Launch the server
uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000

Or use the bundled launcher, which sources .env and prints startup diagnostics:

chmod +x run.sh && ./run.sh

Open http://127.0.0.1:8000 in your browser.

Option B β€” Docker Compose

Spins up the AgriPulse app alongside an Ollama container:

docker-compose up --build

The app is served on http://localhost:8000; Ollama listens on http://localhost:11434. Persistent volumes are created for both the database and Ollama models.

Note: The first run will download the Llama 3.1 model inside the Ollama container β€” attach to it and run ollama pull llama3.1:8b, or pre-pull on the host.

Option C β€” Kubernetes

Manifests are provided as a Kustomize bundle under k8s/:

kubectl apply -k k8s/

Includes namespace, configmap, deployment, service, ingress, and storage resources.


Configuration

All settings are read from environment variables (or a .env file at the project root β€” copy .env.example to get started).

Variable Default Description
SENSOR_MODE simulated simulated (no hardware) or real (Raspberry Pi GPIO)
DATABASE_URL sqlite:///./agripulse.db SQLAlchemy connection string (SQLite or PostgreSQL)
OLLAMA_BASE_URL http://localhost:11434 Ollama API endpoint
OLLAMA_MODEL llama3.1:8b LLM model identifier for the AI Architect & onboarding
HOST 0.0.0.0 Server bind address
PORT 8000 Server port

For PostgreSQL, set DATABASE_URL=postgresql://user:password@localhost:5432/agripulse.


Pages

Page Description
Dashboard Farm selector, live stats, field status, quick actions
Fields Field list & detail, crop cycles, soil & activity timeline
Soil Soil readings, NPK analysis, reading history
Plants Plant health, disease risk, pest pressure
Tasks Task management with priority, status, and filtering
Irrigation Irrigation & fertilization logging and scheduling
Chat AI Architect β€” LLM-powered agronomy assistant
BOM Bill of Materials β€” hardware inventory & status
Setup AI Farm Onboarding β€” describe your farm, review & confirm

API Reference

All REST endpoints are prefixed with /api/v1.

Resource Endpoints
Farms GET/POST /farms/, GET/PUT/DELETE /farms/{id}
Onboarding POST /farms/onboard/confirm β€” create a farm from an AI template
Fields GET/POST /fields/, GET/PUT/DELETE /fields/{id}
Crop Cycles GET/POST /crop-cycles/, GET/PUT/DELETE /crop-cycles/{id}
Soil Readings GET/POST /soil-readings/, GET /soil-readings/latest/{field_id}
Plant Health GET/POST /plant-health/, GET /plant-health/latest/{field_id}
Irrigation GET/POST /irrigation/, POST /irrigation/schedule
Fertilization GET/POST /fertilization/
Harvests GET/POST /harvests/, PUT/DELETE /harvests/{id}
Tasks GET/POST /tasks/, PUT/DELETE /tasks/{id}
Dashboard GET /dashboard/summary, GET /dashboard/alerts
Weather GET /dashboard/weather/{field_id} (Open-Meteo)

WebSocket

Connect to ws://host:8000/ws and send JSON frames with an action field:

Action Payload Description
subscribe β€” Stream real-time sensor data every 2.5 s
get_nodes β€” Request a current node-status snapshot
chat { "messages": [...] } Send a conversation to the AI Architect
onboard { "spec": "farm description" } Stream AI analysis of a farm spec β†’ template
exec_tool { "name", "args" } Execute an actuator command (pump, lights, fans, …)

Inbound message types: data, alert, chat_response, onboard_thought, onboard_template, onboard_error, tool_result.


Project Structure

AgriPulse-EdgeCluster/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py                # FastAPI app, WebSocket endpoint, actuator tools
β”‚   β”œβ”€β”€ routes.py              # REST routers (farms, fields, tasks, onboarding, …)
β”‚   β”œβ”€β”€ models.py              # SQLAlchemy ORM models & Pydantic schemas
β”‚   β”œβ”€β”€ database.py            # Engine & session factory
β”‚   β”œβ”€β”€ websocket_manager.py   # Connection manager & WS action dispatch
β”‚   β”œβ”€β”€ onboarding_service.py  # AI farm-onboarding (Ollama streaming + fallback)
β”‚   β”œβ”€β”€ ollama_service.py      # AI Architect chat service
β”‚   β”œβ”€β”€ sensors.py             # Simulated & real sensor managers
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── Dockerfile
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ *.html                 # One page per view (no framework)
β”‚   └── static/
β”‚       β”œβ”€β”€ css/style.css
β”‚       └── js/{api.js, app.js}
β”œβ”€β”€ k8s/                       # Kubernetes manifests (Kustomize)
β”œβ”€β”€ wiki/                      # Project documentation
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ run.sh                     # Local launcher (sources .env)
└── .env.example

Hardware Bill of Materials

  • 3Γ— Raspberry Pi 5 (16 GB)
  • 1Γ— AI HAT+ Hailo-10H (26 TOPS)
  • 1Γ— Sense HAT
  • 1Γ— NVMe HAT + 512 GB SSD
  • 3Γ— Capacitive Soil Moisture Sensors
  • 1Γ— Industrial pH Probe + ADS1115 ADC
  • 2Γ— DS18B20 Temperature Sensors
  • 1Γ— Global Shutter Camera
  • Actuators: pump, mister, solenoid valve, LED grow lights, fans, relay module
  • IP65 vented enclosure

See wiki/Hardware-BOM.md for sourcing details.


Documentation

In-depth guides live in the wiki/ directory:


Contributing

Contributions are welcome. Please read CONTRIBUTING.md for guidelines and CODE_OF_CONDUCT.md for our community standards before opening a pull request.


Security

Found a vulnerability? Please review SECURITY.md for responsible disclosure instructions β€” do not open a public issue for security-related problems.


License

Released under the MIT License.

About

Edge-native Farm Management Information System on a 3-node Raspberry Pi 5 cluster with Hailo-10H AI acceleration, real-time sensor telemetry, and on-device LLM agronomy (FastAPI + Ollama).

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors