Skip to content

Repository files navigation

AgroSense 🌱

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.

Architecture

ESP32 Sensor Node → Flask Backend → SQLite DB
                        ↕
                   Ollama LLM (DeepSeek)
                        ↕
         Web Dashboard  |  WhatsApp (wacli)

See Website/flow.md for the full system architecture diagram.

Features

  • 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

Tech Stack

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
WhatsApp Go-based CLI tool (wacli)

Project Structure

├── 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

Getting Started

Prerequisites

  • 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 + wacli binary (optional, for WhatsApp integration)

Backend Setup

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 82

The database is auto-created from AgroSenseDB.db.sql on first run.

ESP32 Firmware

cd AgroSenseHardwareSketch
platformio run --target upload

Environment Variables

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

Database Schema

6 tables: userDetails, espDetails, esp_logs, farmDetails, irrigation_rules, notifications, chats

See Website/AgroSenseDB.db.sql for the full schema and seed data.

Irrigation Rule Types

  1. Periodic — Schedule by day-of-week + time window
  2. Moisture-Triggered — Start/stop based on soil moisture thresholds
  3. Rain Delay — Suppress irrigation when rain is forecast
  4. AI Auto-Generated — DeepSeek generates 2–4 optimized rules from farm + sensor + weather context

License

MIT

About

AI-Powered Smart Irrigation for Precision Farming. ESP32 + Flask + Ollama (DeepSeek) + WhatsApp integration for real-time farm monitoring and automated irrigation.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages