AI-Powered Smart Irrigation for Precision Farming
AgroSense is an end-to-end smart farming system that combines ESP32-based IoT hardware with an AI-driven Flask web application. It enables farmers to monitor soil conditions, control irrigation remotely, and get intelligent recommendations through a dashboard or WhatsApp.
ESP32 Sensor Node → Flask Backend → SQLite DB
↕
Ollama LLM (DeepSeek)
↕
Web Dashboard | WhatsApp (wacli)
See Website/flow.md for the full system architecture diagram.
- Real-time Monitoring — Soil moisture, temperature, humidity, water tank level, battery status via ESP32 heartbeat
- Irrigation Control — Manual, periodic (scheduled), moisture-threshold-triggered, and rain-delay rules
- AI Auto-Irrigation — Ollama-powered rule generation based on sensor history, weather forecast, and crop details
- KrishiMitra Chatbot — Context-aware farming assistant with SSE streaming — knows your farm, sensors, and active rules
- WhatsApp Integration — Farmers can check stats and schedule irrigation via WhatsApp messages processed by AI
- Weather Integration — 5-day OpenWeatherMap forecast for informed irrigation decisions
- User Dashboard — Login/register, profile management, live charts, notification center
| Layer | Technology |
|---|---|
| Backend | Flask (Python) |
| Database | SQLite |
| Frontend | Jinja2 + Bootstrap 5 (NiceAdmin theme) + ApexCharts / Chart.js |
| Hardware | ESP32 (Arduino framework, PlatformIO) |
| AI / LLM | Ollama running DeepSeek model locally |
| Weather | OpenWeatherMap API |
Go-based CLI tool (wacli) |
├── Website/ # Flask web application
│ ├── app.py # Main application routes
│ ├── database.py # SQLite helper functions
│ ├── whatsapp_Service.py # WhatsApp polling + AI service
│ ├── AgroSenseDB.db.sql # Database schema + seed data
│ ├── templates/ # Jinja2 HTML templates
│ ├── assets/ # CSS, JS, images, vendor libs
│ └── flow.md # Architecture diagram
│
├── AgroSenseHardwareSketch/ # ESP32 firmware (PlatformIO)
│ ├── platformio.ini
│ └── src/ # Arduino source files
│
├── requirements.txt
└── README.md
- Python 3 + Flask
- Ollama with a DeepSeek model (e.g.
deepseek-v3.2:cloud) - PlatformIO (for ESP32 firmware)
- OpenWeatherMap API key (optional, for weather features)
- WhatsApp account +
waclibinary (optional, for WhatsApp integration)
cd Website
pip install -r ../requirements.txt
# Set environment variables:
# OWM_API_KEY=your_openweathermap_key
# SECRET_KEY=your_flask_secret_key
# WHATSAPP_TO=... (optional, for WhatsApp)
# WHATSAPP_CHAT_ID=... (optional)
flask run --debug -h 0.0.0.0 -p 82The database is auto-created from AgroSenseDB.db.sql on first run.
cd AgroSenseHardwareSketch
platformio run --target upload| Variable | Description | Required |
|---|---|---|
OWM_API_KEY |
OpenWeatherMap API key | No (weather features) |
SECRET_KEY |
Flask session secret | No (has default) |
WHATSAPP_TO |
Target WhatsApp number | No (WhatsApp features) |
WHATSAPP_CHAT_ID |
WhatsApp group/contact ID | No (WhatsApp features) |
ESP_ID |
Default ESP MAC address | No |
6 tables: userDetails, espDetails, esp_logs, farmDetails, irrigation_rules, notifications, chats
See Website/AgroSenseDB.db.sql for the full schema and seed data.
- Periodic — Schedule by day-of-week + time window
- Moisture-Triggered — Start/stop based on soil moisture thresholds
- Rain Delay — Suppress irrigation when rain is forecast
- AI Auto-Generated — DeepSeek generates 2–4 optimized rules from farm + sensor + weather context
MIT