Skip to content

Nav-cmd/StorAgri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

StorAgri โ€” Smart IoT Post-Harvest Storage Monitor

Flutter React Python Flask Firebase C++ ESP32 Dart


Status AI Detection IoT Multilingual License


Developer

GitHub Email


๐Ÿ“‹ Table of Contents


๐ŸŒ Overview

StorAgri is a comprehensive, full-stack smart agriculture platform that integrates IoT sensing, Artificial Intelligence, cloud computing, and cross-platform mobile development into a unified post-harvest crop storage monitoring solution.

Smallholder farmers in Sri Lanka lose 30โ€“40% of their harvest annually due to inadequate storage monitoring โ€” a silent crisis that threatens both farmer income and national food security. StorAgri directly addresses this challenge by deploying affordable IoT hardware inside storage facilities to continuously capture environmental conditions. This raw data travels through a Python Flask backend where AI models transform it into actionable insights: a real-time Storage Health Score, a 72-hour spoilage forecast, and automated multilingual alerts delivered to farmers before losses occur.

The system operates across two interfaces:

  • A React.js admin dashboard for supervisors and agricultural coordinators to monitor fleets of sensors, farmers, and devices
  • A Flutter mobile application for farmers โ€” featuring live environmental readings, AI-driven insights, and a built-in AI visual spoilage detection tool that analyses uploaded crop images to identify early signs of disease or deterioration

StorAgri was designed from the ground up to be affordable, scalable, and inclusive, with full support for Sinhala, Tamil, and English, making it genuinely usable in diverse Sri Lankan farming communities.


๐Ÿ”ด Problem Statement

Post-harvest spoilage is a multi-dimensional crisis for Sri Lankan smallholder farmers:

Challenge Real-World Impact
Spoilage rates of 30โ€“40% per season Direct and severe income loss
No real-time environmental monitoring Intervention is delayed until visible damage occurs
Manual inspection โ€” slow and subjective Inaccurate decisions, inconsistent assessment
Tropical climate extremes Temperature spikes and humidity surges rapidly accelerate spoilage
Chain-reaction spoilage in stacked storage One affected unit spreads deterioration to neighbouring produce
Limited digital literacy in rural areas Existing technology platforms are inaccessible to farmers
Unreliable rural internet connectivity Always-on cloud services are impractical without offline capability

StorAgri addresses every one of these dimensions through a deliberate combination of accessible hardware, intelligent software, and farmer-first design.


๐Ÿ—๏ธ System Architecture

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘                      StorAgri โ€” System Architecture                 โ•‘
โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฆโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฆโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฃ
โ•‘   IoT Layer       โ•‘    Intelligence Layer     โ•‘   Presentation Layer  โ•‘
โ•‘                   โ•‘                          โ•‘                       โ•‘
โ•‘  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ•‘  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ•‘  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ•‘
โ•‘  โ”‚   ESP32 MCU  โ”‚  โ•‘  โ”‚  Python Flask API  โ”‚  โ•‘  โ”‚  React Admin    โ”‚  โ•‘
โ•‘  โ”‚  DHT11 Temp  โ”‚โ”€โ”€โ•ฌโ”€โ”€โ”‚  AI Scoring Engine โ”‚  โ•‘  โ”‚  Dashboard      โ”‚  โ•‘
โ•‘  โ”‚  MQ-135 Gas  โ”‚  โ•‘  โ”‚  Spoilage Forecast โ”‚  โ•‘  โ”‚  (Web Browser)  โ”‚  โ•‘
โ•‘  โ”‚  WiFi Tx     โ”‚  โ•‘  โ”‚  Image Detection   โ”‚  โ•‘  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ•‘
โ•‘  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ•‘  โ”‚  SocketIO Broadcastโ”‚  โ•‘                       โ•‘
โ•‘                   โ•‘  โ”‚  Pandas Analytics  โ”‚  โ•‘  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ•‘
โ•‘                   โ•‘  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ•‘  โ”‚  Flutter Mobile โ”‚  โ•‘
โ•‘                   โ•‘           โ”‚              โ•‘  โ”‚  App (iOS & Android)โ•‘
โ•‘                   โ•‘  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ•‘  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ•‘
โ•‘                   โ•‘  โ”‚  Firebase Realtime  โ”‚  โ•‘                       โ•‘
โ•‘                   โ•‘  โ”‚  Database + Auth    โ”‚  โ•‘                       โ•‘
โ•‘                   โ•‘  โ”‚  + Cloud Messaging  โ”‚  โ•‘                       โ•‘
โ•‘                   โ•‘  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ•‘                       โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฉโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฉโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

End-to-End Data Flow:

[ESP32 Sensor Node]
      โ”‚  HTTP POST /sensor-data (JSON payload)
      โ–ผ
[Flask Backend]
  โ”œโ”€โ”€ Clean & classify sensor values (Safe / Warning / Critical)
  โ”œโ”€โ”€ Compute Storage Health Score + Spoilage Forecast
  โ”œโ”€โ”€ Write to Firebase: live data, history, alerts, analytics, reports
  โ”œโ”€โ”€ Broadcast via SocketIO โ†’ React Dashboard (real-time)
  โ””โ”€โ”€ Trigger Firebase Cloud Messaging โ†’ Flutter Mobile (push alerts)
      โ”‚
      โ”œโ”€โ”€ [React Admin Dashboard]  โ†  Firebase Realtime DB reads
      โ””โ”€โ”€ [Flutter Farmer App]     โ†  Firebase Realtime DB reads

๐Ÿงฐ Technology Stack

๐Ÿ–ฅ๏ธ Admin Panel โ€” Web Frontend

Technology Version Role
React.js Latest Admin dashboard SPA framework
CSS3 (Advanced) โ€” Custom animations, glassmorphism, responsive layout
SocketIO Client โ€” WebSocket live sensor data reception
Firebase Web SDK โ€” Real-time data binding, authentication

๐Ÿ“ฑ Farmer Application โ€” Mobile Frontend

Technology Version Role
Flutter Latest Cross-platform mobile app framework (iOS & Android)
Dart Latest Flutter's application language
Firebase Flutter SDK โ€” Realtime database, auth, cloud messaging integration
Custom CRT Chart Widget โ€” Animated live sensor trend visualization with glow effects
image_picker โ€” Camera and gallery access for AI crop scanning

โš™๏ธ Backend Server

Technology Version Role
Python 3 3.x Core server-side language
Flask Latest RESTful API framework
Flask-SocketIO โ€” WebSocket real-time broadcasting to connected clients
Pandas โ€” Sensor history analysis, report computation, data aggregation
Firebase Admin SDK โ€” Server-side Firebase read/write operations

โ˜๏ธ Cloud & Database

Service Provider Role
Firebase Realtime Database Google Live sensor data, user records, alerts, AI analytics, reports
Firebase Authentication Google Role-based access control (Admin / Farmer)
Firebase Cloud Messaging Google Push notifications to farmer mobile devices

โšก IoT Hardware & Firmware

Component Type Role
ESP32 32-bit MCU (Espressif) Main processing unit with built-in WiFi for data transmission
DHT11 Temperature & Humidity Sensor Environmental condition measurement
MQ-135 Metal Oxide Gas Sensor Air quality and gas concentration detection
Breadboard Circuit Prototyping Sensor integration and wiring
C++ (Arduino Framework) Firmware Language Sensor polling, calibration, risk scoring, HTTP transmission

๐Ÿค– AI & Machine Learning

Technology Role
Python AI Models Storage Health Score calculation, spoilage risk prediction
Image Classification Model Visual crop spoilage detection from uploaded images
Pandas Historical trend analysis, average/peak environmental metrics
SocketIO Real-time AI prediction delivery to dashboards

โœจ Key Features

๐ŸŒก๏ธ Real-Time Environmental Monitoring

Continuous, automatic monitoring of three critical post-harvest parameters across all registered storage units:

  • Temperature (ยฐC) via DHT11 sensor
  • Humidity (%) via DHT11 sensor
  • Gas Concentration / Air Quality (ppm, ratio) via MQ-135 sensor

Each reading is automatically classified into one of three states with colour-coded indicators:

Status Colour Meaning
โœ… Safe / Fresh Green All parameters within acceptable thresholds
โš ๏ธ Warning Yellow/Orange At least one parameter approaching risk threshold
๐Ÿ”ด Critical Red One or more parameters exceeded โ€” immediate action required

๐Ÿค– AI-Powered Spoilage Intelligence

Storage Health Score

A normalized composite metric computed by the Flask AI engine from temperature, humidity, and gas ratio. Displayed as a circular gauge on both the admin dashboard and farmer mobile app, giving an instant snapshot of overall storage safety.

72-Hour Spoilage Prediction

Predictive analytics model forecasts the expected deterioration timeline across the next 72 hours. Displayed as a bar chart on the farmer insights page with clear risk milestones, enabling farmers to plan interventions before spoilage becomes irreversible.

AI Visual Spoilage Detection (Fully Implemented)

Farmers can upload a photograph of their stored crop (via device camera or gallery) directly from the StorAgri mobile app. The backend AI model analyses the image for:

  • Visible mould growth
  • Discolouration and surface deterioration
  • Early-stage pest infestation
  • Abnormal texture or structural changes

The system returns a classification result with confidence indication, enabling early detection before damage spreads.


๐Ÿ“Š Comprehensive Reporting

The admin panel generates downloadable PDF reports across five categories:

Report Type Content
Monthly Performance Average sensor readings, alert frequency, system uptime
Farmer Activity Per-farmer storage events, alert history, risk incidents
Spoilage Prevention AI-predicted risks, preventive actions taken, outcomes
Device Health Device uptime, connectivity stats, sensor calibration status
Regional Analysis District-level aggregated spoilage trends and environmental profiles

๐Ÿ”” Alert Management System

  • Automated alerts generated when sensor thresholds are breached
  • In-app push notifications delivered to farmer mobile devices via Firebase Cloud Messaging
  • Admin acknowledgement system with confirmation notification sent back to farmers
  • Full alert record with type, severity, timestamp, storage location, and delivery status

๐Ÿช Multi-Storage Unit Management

Register and monitor multiple independent storage environments per farm:

  • Main Storage Shed
  • Onion Room
  • Potato Cellar
  • Any custom unit (expandable)

Each unit displays current condition, last update timestamp, and status colour. New units can be added dynamically from the farmer app.


๐Ÿ”’ Security & Compliance

  • Firebase-authenticated role-based access (Admin role / Farmer role)
  • Secure session management
  • Comprehensive audit log trail recording all system actions with timestamps and user attribution

๐Ÿ–ฅ๏ธ Admin Dashboard

The React-based admin panel provides full system oversight and management across 12 functional pages:

Page Key Components
Login / Register Secure Firebase email-password authentication
Dashboard Overview KPI cards (total farmers, active storages, online devices, daily alerts); interactive analytics charts; recent alert feed; high-risk storage list; system health metrics
Farmer Management Farmer registration, verification, status management; regional filtering and search; storage unit assignment
IoT Device Management Device registration, online/offline status monitoring; per-device sensor readings; location and farmer association
Alert Management Alert listing with severity colour codes; acknowledgement controls; response time tracking; notification delivery status
Real-Time Sensor Monitoring Live min/max/average readings for temperature, humidity, gas across all devices; interactive time-series line and bar charts
AI Analytics & Spoilage Intelligence Model accuracy KPI; storage-wise spoilage risk cards; confidence levels; feature importance radar chart; AI trend graphs
Market Intelligence Planned module for crop market pricing and sell-timing advisory
Reports & Analytics Report summary KPIs; visualizations; report template selection; PDF generation and download
System Settings Alert threshold configuration; notification settings; language preferences; security options; integration management
Audit Logs Chronological activity log with user, action, and timestamp; compliance traceability
Admin Profile Personal information management; role and access configuration

๐Ÿ“ฑ Farmer Mobile Application

The Flutter cross-platform mobile app is the farmer's primary interface โ€” designed for simplicity, speed, and accessibility in rural conditions:

Screen Description
Welcome / Landing App branding and introductory screen
Login Firebase authentication with secure credentials
Register New farmer account creation with farm and crop details
Home Dashboard Three live sensor tiles (Temp / Humidity / Gas) with Safe/Warning/Critical colour coding; circular Storage Health Score gauge; quick action buttons to Alerts, Storage, AI Scan, and Insights
Alerts Page Chronological colour-coded alert cards with severity, description, affected storage unit, and timestamp
Temperature Alert Detail Full alert breakdown with live CRT-style animated trend graph and actionable corrective guidance
Humidity Alert Detail Identical structure to temperature page โ€” humidity-specific data, trend, and recommendations
Gas Level Alert Detail Gas concentration alert with live trend visualization and safety guidance
Storage Component Page Grid of all registered storage units with status indicators; timestamp of last update; Add New Storage Unit function
Insights Page AI health score visualizer; spoilage prediction (estimated risk in hours); 72-hour forecast bar chart; AI-generated crop-specific recommendations
AI Spoilage Detection Image upload interface supporting camera capture and gallery selection; supported format listing; backend AI analysis result display
User Profile Personal details; farmer ID and contact information; farm location and crop preferences; notification settings; account security; logout

โš™๏ธ IoT Hardware Layer

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           ESP32 IoT Sensor Node                     โ”‚
โ”‚                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚ DHT11 Sensor      โ”‚   โ”‚ MQ-135 Gas Sensor     โ”‚   โ”‚
โ”‚  โ”‚ โ”œ Temperature ยฐC  โ”‚   โ”‚ โ”œ Air Quality (ppm)   โ”‚   โ”‚
โ”‚  โ”‚ โ”” Humidity %      โ”‚   โ”‚ โ”” Gas Ratio vs. Base  โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                โ”‚                      โ”‚              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚            ESP32 Microcontroller               โ”‚  โ”‚
โ”‚  โ”‚  โ”œ Sensor polling loop                        โ”‚  โ”‚
โ”‚  โ”‚  โ”œ Gas baseline calibration (startup)         โ”‚  โ”‚
โ”‚  โ”‚  โ”œ Risk score computation                     โ”‚  โ”‚
โ”‚  โ”‚  โ”œ Storage condition classification           โ”‚  โ”‚
โ”‚  โ”‚  โ”œ Serial Monitor debug output                โ”‚  โ”‚
โ”‚  โ”‚  โ”” WiFi โ†’ HTTP POST /sensor-data (JSON)       โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

C++ Firmware Execution Flow:

Boot โ†’ WiFi Connect โ†’ MQ-135 Baseline Calibration
  โ””โ”€โ–บ Polling Loop (continuous):
        โ”œโ”€โ”€ Read DHT11 โ†’ temperature (ยฐC) + humidity (%)
        โ”œโ”€โ”€ Read MQ-135 โ†’ raw gas value โ†’ smoothed โ†’ gas ratio
        โ”œโ”€โ”€ Compute risk score from (temp + humidity + gas ratio)
        โ”œโ”€โ”€ Classify: Fresh | Partially Spoiled | Spoiled
        โ”œโ”€โ”€ Print to Serial Monitor (local debug)
        โ””โ”€โ”€ If WiFi OK โ†’ JSON payload โ†’ POST /sensor-data

Sample JSON Payload to Backend:

{
  "device_id": "ESP32-001",
  "temperature": 28.4,
  "humidity": 76.2,
  "gas_level": 412,
  "gas_ratio": 1.34,
  "risk_score": 67,
  "condition": "Warning"
}

๐Ÿค– AI & Machine Learning Engine

Sensor-Based Predictive Analytics

The Flask backend houses the core AI engine that processes every incoming sensor reading:

Input โ†’ Processing โ†’ Output:

Sensor Reading (temp, humidity, gas_level, gas_ratio)
      โ”‚
      โ–ผ
Risk Score Calculation
      โ”‚
      โ–ผ
Storage Health Score (0โ€“100 normalized safety metric)
      โ”‚
      โ”œโ”€โ”€ Spoilage Prediction (estimated hours to risk threshold)
      โ”œโ”€โ”€ 72-Hour Condition Forecast (time-series projection)
      โ”œโ”€โ”€ Crop-Specific Recommendations (action guidance)
      โ””โ”€โ”€ Alert Classification (Safe / Warning / Critical)

Firebase Write Operations per Sensor Reading:

Firebase Path Data Written
sensor_data/ Live current reading
sensor_history/ Historical time-series record
ai_analytics/ Health score, prediction, recommendations
alerts/ Alert record if threshold breached
reports/ Running aggregate for report generation

Visual Spoilage Detection โ€” Image-Based AI (Implemented)

The StorAgri mobile app features a dedicated AI Spoilage Detection screen that enables farmers to scan stored produce using their smartphone:

Detection Pipeline:

Farmer opens AI Scan page
      โ”‚
      โ”œโ”€โ”€ Selects: [๐Ÿ“ท Camera] or [๐Ÿ–ผ๏ธ Gallery]
      โ”‚
      โ–ผ
Image captured / selected from device
      โ”‚
      โ–ผ
Image uploaded to Flask backend AI endpoint
      โ”‚
      โ–ผ
Image preprocessing โ†’ Feature extraction โ†’ Classification model
      โ”‚
      โ–ผ
Result returned: Spoilage classification + Confidence level
      โ”‚
      โ–ผ
Displayed on mobile screen with recommended action

Detectable Conditions:

  • ๐ŸŸข Healthy / No visible spoilage
  • ๐ŸŸก Early-stage spoilage (discolouration, texture changes)
  • ๐Ÿ”ด Mould growth / Active spoilage
  • ๐Ÿ”ด Pest infestation indicators

Pandas-Based Report Analytics

The backend uses Pandas to compute summary statistics from Firebase sensor history for report generation:

Metric Computed For
Average Temperature Per storage unit per period
Maximum Temperature Peak risk identification
Average Humidity Environmental consistency analysis
Average Gas Level Air quality trend
Average Health Score Overall storage safety rating

๐Ÿ”Œ Backend API

The Flask server acts as the central intelligence and data-routing layer of the StorAgri ecosystem:

REST Endpoint

Endpoint Method Auth Description
/sensor-data POST Device Key Receives live sensor JSON from ESP32 microcontroller

WebSocket Events (SocketIO)

Event Direction Description
live_data Server โ†’ Client Broadcasts real-time sensor update to all connected React and Flutter clients
alert_trigger Server โ†’ Client Notifies dashboard of newly generated alert

Firebase Cloud Messaging

Push notifications are triggered server-side when a sensor reading breaches a configured threshold. The notification payload includes:

  • Alert type (Temperature / Humidity / Gas)
  • Severity level
  • Storage unit name
  • Recommended corrective action
  • Timestamp

๐Ÿ—„๏ธ Database Design

Firebase Realtime Database is organized into logically separated nodes:

Firebase Realtime Database Root
โ”‚
โ”œโ”€โ”€ users/
โ”‚   โ”œโ”€โ”€ {admin_id}/        โ†’ name, email, role: "admin"
โ”‚   โ””โ”€โ”€ {farmer_id}/       โ†’ name, email, role: "farmer", farm_location
โ”‚
โ”œโ”€โ”€ farmers/
โ”‚   โ””โ”€โ”€ {farmer_id}/       โ†’ full profile, district, crops, storage units
โ”‚
โ”œโ”€โ”€ devices/
โ”‚   โ””โ”€โ”€ {device_id}/       โ†’ farmer_id, location, crop_type, status, last_seen
โ”‚
โ”œโ”€โ”€ storage_units/
โ”‚   โ””โ”€โ”€ {unit_id}/         โ†’ name, farmer_id, device_id, condition, last_updated
โ”‚
โ”œโ”€โ”€ sensor_data/           โ†’ latest live readings per device
โ”‚   โ””โ”€โ”€ {device_id}/       โ†’ temp, humidity, gas, health_score, condition, timestamp
โ”‚
โ”œโ”€โ”€ sensor_history/        โ†’ time-series records per device
โ”‚   โ””โ”€โ”€ {device_id}/
โ”‚       โ””โ”€โ”€ {record_id}/   โ†’ full sensor snapshot with timestamp
โ”‚
โ”œโ”€โ”€ ai_analytics/          โ†’ AI outputs per device
โ”‚   โ””โ”€โ”€ {device_id}/       โ†’ health_score, spoilage_hours, forecast, recommendations
โ”‚
โ”œโ”€โ”€ alerts/                โ†’ generated alert records
โ”‚   โ””โ”€โ”€ {alert_id}/        โ†’ type, severity, device_id, farmer_id, message, acknowledged
โ”‚
โ”œโ”€โ”€ reports/               โ†’ computed report aggregates
โ”‚   โ””โ”€โ”€ {report_id}/       โ†’ type, period, avg_temp, avg_humidity, avg_gas, score
โ”‚
โ””โ”€โ”€ audit_logs/            โ†’ full activity trail
    โ””โ”€โ”€ {log_id}/          โ†’ user, action, timestamp, affected_entity

๐ŸŒ Multilingual Support

StorAgri is engineered for linguistic inclusivity across Sri Lanka's three main languages:

Language Script Coverage
๐Ÿ‡ฌ๐Ÿ‡ง English Latin Full system โ€” Admin Panel + Mobile App
๐Ÿ‡ฑ๐Ÿ‡ฐ Sinhala เทƒเท’เถ‚เท„เถฝ Mobile App โ€” all pages, alerts, recommendations
๐Ÿ‡ฑ๐Ÿ‡ฐ Tamil เฎคเฎฎเฎฟเฎดเฏ Mobile App โ€” all pages, alerts, recommendations

Language preference is configurable per user through the Profile settings page. Alert messages, condition descriptions, and AI recommendations are served in the selected language. The system architecture ensures language strings are decoupled from business logic, enabling seamless extension to additional languages in future iterations.


๐Ÿ”„ Development Methodology

StorAgri was built using an Agile Sprint-Based approach across four structured development iterations:

Sprint Focus Area Key Deliverables
Sprint 1 Planning, Design & IoT Foundation Project scope finalized; system architecture designed; database schema defined; ESP32 connected to DHT11 + MQ-135; basic sensor data capture verified
Sprint 2 Backend & Core Frontend Flask API operational; Firebase authentication and Realtime DB integrated; basic React admin pages rendered; Flutter app scaffolded with live sensor display
Sprint 3 AI Intelligence & Alerts Storage Health Score engine implemented; spoilage prediction model integrated; push notifications configured; multilingual alert delivery enabled; decision-support dashboard built
Sprint 4 Testing, Deployment & Refinement 30 structured test cases executed (admin + farmer suites); cloud deployment completed; user feedback collected; performance optimizations applied; documentation finalized

Why Agile for StorAgri?

Factor How Agile Helps StorAgri
Evolving requirements Farmer feedback reshapes alert thresholds and UI iteratively
IoT uncertainty Sensor behavior in real storage differs from lab โ€” iterative calibration is essential
AI model refinement Health score accuracy improves with each sprint of real data
Risk isolation Sprint-scoped failures don't cascade across the entire system
Early value delivery Core monitoring dashboard delivers value from Sprint 2 onwards

โœ… Testing & Verification

StorAgri underwent structured testing across two complete test suites โ€” one for admin users and one for farmers. All test cases were executed by named independent testers and all passed successfully.

Admin Test Suite (AT1 โ€“ AT19)

Test ID Test Name Result
AT1 Admin Login Validation โœ… Pass
AT2 Admin Register Validation โœ… Pass
AT3 Dashboard Display โœ… Pass
AT4 Farmer Registration โœ… Pass
AT5 Farmer Verification โœ… Pass
AT6 Alert Management โœ… Pass
AT7 Alert Acknowledgement โœ… Pass
AT8 Device Status Monitoring โœ… Pass
AT9 Alert Acknowledgement Notification โœ… Pass
AT10 Sensor Readings View โœ… Pass
AT11 AI Analytics Prediction โœ… Pass
AT12 Monthly Performance Report (PDF) โœ… Pass
AT13 Farmer Activity Report โœ… Pass
AT14 Spoilage Prevention Report โœ… Pass
AT15 Device Health Report โœ… Pass
AT16 Regional Analysis Report โœ… Pass
AT17 Settings Update โœ… Pass
AT18 Audit Logs View โœ… Pass
AT19 Profile Update โœ… Pass

Farmer Test Suite (FT1 โ€“ FT11)

Test ID Test Name Result
FT1 Farmer Login Validation โœ… Pass
FT2 Dashboard Display โœ… Pass
FT3 Safe Storage Condition Display โœ… Pass
FT4 Temperature Alert Generation โœ… Pass
FT5 Humidity Alert Generation โœ… Pass
FT6 Gas Level Alert Generation โœ… Pass
FT7 Alert Detail View โœ… Pass
FT8 Storage Monitoring Page โœ… Pass
FT9 Insights / AI Analytics Page โœ… Pass
FT10 Spoilage Prediction Report โœ… Pass
FT11 Profile & Notification Settings โœ… Pass

All 30 test cases passed. AI analytics prediction, sensor reading accuracy, PDF report generation, push notification delivery, and device status monitoring were verified as fully operational.


โš ๏ธ Known Limitations & Future Enhancements

Current Limitations

Feature Status Reason
Twilio SMS Alerts Partially implemented Premium API subscription required for full deployment
AI Visual Spoilage Detection Implemented โ€” optimization ongoing Image preprocessing and backend model consistency require further refinement
Offline Synchronization Partial Conflict resolution for local-to-Firebase sync needs improvement
Multi-Storage Scalability Foundation built Large-scale concurrent multi-farm architecture needs further work
DHT22 Sensor DHT11 used as substitute Component availability and cost constraints at build time
Full Multilingual Optimization Foundation implemented Font compatibility and dynamic layout alignment need improvement

Planned Future Enhancements

Phase 1 โ€” Stability & Core Completion

  • GSM-module-based SMS alert delivery (eliminating dependency on paid third-party services)
  • DHT22 sensor upgrade (wider range, higher precision)
  • Offline-first data caching with automatic conflict-resolved synchronization

Phase 2 โ€” AI Advancement

  • Convolutional Neural Network (CNN) deep learning upgrade for visual spoilage detection
  • Expanded training dataset for improved mould, pest, and disease classification accuracy
  • Adaptive alert thresholds that self-calibrate based on historical crop-specific data

Phase 3 โ€” Accessibility & Usability

  • Voice-based interaction and speech alerts for low-literacy users
  • Additional language support (regional dialects)
  • SMS-based alert delivery without internet dependency

Phase 4 โ€” Automation & Scale

  • Smart actuator integration (automated ventilation, cooling, humidity controllers)
  • Multi-farm / cooperative network monitoring from a single admin platform
  • Scalable cloud infrastructure for high-volume real-time data processing

Phase 5 โ€” Expansion

  • Encrypted data transmission and advanced role-based access control
  • Market intelligence module with live crop pricing and sell-timing advisory
  • Adaptation for deployment in other developing regions facing similar agricultural challenges

๐Ÿ‘จโ€๐Ÿ’ป About the Developer

Hi, I'm Naveen Nagendran โ€” a Software Engineer with a passion for building real-world systems that sit at the intersection of IoT, AI, and full-stack development.

StorAgri is my first complete end-to-end project. I designed and built every layer of the stack independently โ€” from flashing C++ firmware onto an ESP32 microcontroller, to engineering a Python Flask AI backend, to shipping a cross-platform Flutter mobile app and a React admin dashboard, all connected through Firebase in real time.

What I built across this project:

Layer Technologies Used
๐Ÿ“ฑ Mobile App (Farmer) Flutter, Dart, Firebase SDK
๐Ÿ–ฅ๏ธ Web Dashboard (Admin) React.js, CSS3, SocketIO
โš™๏ธ Backend API Python, Flask, Flask-SocketIO, Pandas
๐Ÿค– AI Engine Python ML models, image classification
โ˜๏ธ Cloud & Database Firebase Realtime DB, Firebase Auth, FCM
โšก IoT Firmware C++, Arduino framework, ESP32, DHT11, MQ-135

Project context:

  • Built to solve post-harvest crop loss for smallholder farmers in Sri Lanka
  • Supports Sinhala, Tamil, and English โ€” designed for real-world rural accessibility
  • Includes AI visual spoilage detection, predictive analytics, and real-time IoT monitoring
  • Designed and delivered solo across planning, design, implementation, testing, and deployment


StorAgri ย โ€ขย  Protecting harvests. Empowering farmers. Sustaining futures.


IoT Monitoring AI Engine Mobile Backend Multilingual


Built for the farmers of Sri Lanka โ€” and the world's smallholder farming communities beyond.

About

๐ŸŒพ Full-stack IoT + AI system that monitors crop storage conditions in real time โ€” ESP32 sensors, Python Flask backend, Firebase, Flutter mobile app, React admin dashboard, and AI-powered spoilage detection. Built solo.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors