back to work
2026 · iot · machine learning · optimization

Smart Irrigation.

stack
  • fastapi
  • react
  • python
  • postgresql
  • influxdb
  • mqtt
  • scikit-learn
  • docker
status
live
dilan/smart-irrigation
live
activity pulse
fastapireactpython
overview

An end-to-end, IoT-enabled, ML-driven decision-support platform designed for quota-based irrigation schemes in tropical regions (specifically modeled on Sri Lanka's Udawalawe RBMC/LBMC schemes). The system automates field-level irrigation control using real-time sensors, monitors crop health using Sentinel-2 satellite imagery, forecasts water supply/demand via time-series models, and uses multi-criteria optimization to recommend crops and allocate agricultural land under water quotas.

approach

Monorepo architecture using NGINX as an API Gateway routing traffic to multiple containerized FastAPI microservices. Utilizes PostgreSQL for relational metadata, InfluxDB for time-series sensor telemetry, MongoDB for user authentication records, and Redis for performance caching. Fronted by a React dashboard and connected via Mosquitto MQTT for real-time ESP32 sensor ingestion, backed by Pyomo/PuLP optimization solvers.

functionality

IoT smart water management

Automates field-level water release using ESP32 sensor telemetry streamed via Mosquitto MQTT to InfluxDB, evaluating local forecasts before triggering valve control states.

Satellite crop health monitoring

Sentinel-2 satellite imaging computes NDVI and NDWI vegetation health indices, validated using a MobileNet CNN disease classifier on user-uploaded field photos.

ML time-series forecasting

Dual-tier forecasting system with ARIMA baselines and LSTM models predicting rainfall, reservoir levels, and canal demand over a 14-day horizon with SMS alerting.

Fuzzy-TOPSIS recommender

Multi-criteria decision making under uncertainty that ranks 30 crop candidates per field based on dynamic soil pH, electrical conductivity, size, and terrain features.

Constrained land allocation

Mixed-Integer Linear Programming (MILP) solver in PuLP/Pyomo maximizing command-area agricultural profit under seasonal water quota, risk tolerance, and policy constraints.

case study

Problem

The Udawalawe reservoir dry zone irrigation scheme (16,000+ hectares) suffers from low water use efficiency (30-50%) due to traditional flood irrigation on fixed schedules. Smallholders lack real-time soil telemetry or crop health monitoring, and administrators cannot adjust crop land and water allocations dynamically when monsoonal weather cycles or harvest market prices shift mid-season.

Solution

ASICOP (Adaptive Smart Irrigation and Crop Optimization Platform) is a microservice-based decision-support system that closes the loop between water availability, remote sensing, and land allocation. By dynamically linking upstream reservoir storage and weather forecasts (F3) to field-level sensor actuation (F1) and satellite crop health stress indexes (F2), the platform models multi-dimensional resource limits in a custom optimization solver (F4) to compute high-yield, quota-feasible crop allocation plans.

technical architecture
01

Microservice Mesh & Gateway

  • FastAPI microservices handling authentication (8001), telemetry/irrigation (8002), time-series forecasting (8003), and land optimization (8004).
  • Centralized NGINX API Gateway routing requests, enforcing rate limits, and handling TLS termination.
  • React 18 frontend dashboard using TanStack Query, Leaflet maps with GeoJSON field boundaries, and Recharts visualization plots.
02

Heterogeneous Data Layer

  • PostgreSQL database via SQLAlchemy managing crop models, suitability metrics, and historical metadata.
  • InfluxDB time-series database optimized for storing high-frequency sensor readings (moisture, temperature, humidity).
  • MongoDB handling unstructured authentication files, Redis for response caching, and Mosquitto MQTT broker for streaming telemetry.
03

Optimization & ML Engine

  • LightGBM price predictor utilizing a 24-feature pipeline to forecast harvest prices and price volatility risk.
  • Fuzzy-TOPSIS algorithm scoring crop suitability across physical and climatic parameters.
  • PuLP/Pyomo linear solver maximizing expected farm yields and profits subject to water quotas, policy restrictions, and risk parameters.
request flows top → bottom
system diagram
1. Clients & Edge Layer

Web Dashboard

React 18 • Recharts

Mobile App (PWA)

Farmer Control Panel

IoT Telemetry Nodes

ESP32 • Soil Sensor Actuators

2. Reverse Proxy & Gateway

NGINX API Gateway

TLS Termination • Rate Limiting • CORS Enforcement • Endpoint Routing (Port 80/443)

3. FastAPI Microservices

Auth (8001)

JWT-based roles & permissions (Farmer / Admin).

Irrigation (8002)

Telemetry ingest, thresholds, & closed-loop valves.

Forecast (8003)

ARIMA/LSTM weather & reservoir inflow predictors.

ACA-O (8004)

Fuzzy-TOPSIS ranks & PuLP crop allocation engine.

4. Data & Messaging Layer
PostgreSQLSuitability Specs
InfluxDBTelemetry Series
MongoDBAuth Records
Redis CacheTTL Buffering
MQTT BrokerMosquitto Broker
5. Observability Stack
PrometheusMetrics collection
|
GrafanaVisual Dashboards
key contributions
  1. 01Lead Developer (F4 Optimization): Designed and implemented the Adaptive Crop & Area Optimization (ACA-O) service in Python, utilizing FastAPI and SQLAlchemy.
  2. 02Multi-Criteria Recommender: Built a Fuzzy-TOPSIS suitability scoring engine to rank 30 crop candidates per field based on dynamic soil pH, electrical conductivity, and geographic terrain data.
  3. 03ML Price Forecasting: Developed a LightGBM pricing model featuring a 24-feature pipeline tracking Sri Lankan monsoonal seasonality, climate indicators, and price lag thresholds.
  4. 04Mathematical Optimization: Implemented a Mixed-Integer Linear Programming (MILP) model using PuLP/Pyomo to optimize regional crop area allocation under strict water quota and policy constraints.
  5. 05Full-Stack Integration: Connected backend ML inference to a React dashboard using TanStack Query, rendering real-time crop suitability cards and Recharts data visualizations.
security and reliability
  • Microservice Freshness Metadata: Standardized response contracts containing live status, data quality, and staleness details to allow graceful degradation to historical averages.
  • FastAPI Lifespan Memory Optimization: Restructured startup routines to pre-load the 2.6GB Random Forest crop model into system memory, preventing latency bottlenecks.
  • Caching Optimization: Configured Redis caches with 10-minute TTLs for heavy forecast summaries and suitability rankings to drop API query time under 80ms.
interview talking points
  • Why combining satellite NDVI imagery with ground photo CNN classification reduces false positives in disease detection.
  • How to design an optimal land allocation strategy under strict water budget constraints.
  • How to cache complex multi-criteria scoring calculations using Redis to drop latency from 2.5s to under 80ms.
  • Why a microservices architecture is necessary when scaling heterogeneous databases (InfluxDB, PostgreSQL, MongoDB) in a single platform.