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