Smart Agriculture Platform with IoT Monitoring, Blockchain NFT Traceability & AI-Powered Insights
About โข Features โข Demo โข Tech Stack โข Setup โข Blockchain โข API
Agroflow is a comprehensive smart agriculture platform that bridges the gap between traditional farming and modern technology. It combines IoT sensor monitoring, blockchain-based traceability, and AI-powered recommendations to help farmers optimize their operations while providing consumers with transparent, verifiable information about their food's origin.
- Lack of Transparency โ Consumers have no way to verify if produce is truly organic or where it came from
- Manual Monitoring โ Farmers manually check soil/weather conditions, leading to inefficiencies
- Food Fraud โ Fake organic labels and untraceable supply chains erode consumer trust
- Data Silos โ Farming data isn't leveraged for intelligent decision-making
Agroflow provides an end-to-end platform that:
- ๐ก Monitors farms in real-time using ESP32 IoT sensors (temperature, humidity, soil moisture)
- ๐ Creates immutable blockchain records for every harvest batch as NFTs on Polygon
- ๐ฑ Enables consumer verification by scanning QR codes to see the complete journey of their food
- ๐ค Delivers AI-powered insights via a multilingual chatbot (8+ Indian languages)
- ๐ง Automates irrigation based on soil moisture thresholds
- Live sensor data from ESP32 devices (DHT22 + Soil Moisture)
- Beautiful dashboard with trend charts and analytics
- Automatic data logging to Supabase every 30 seconds
- Alert system for critical conditions (low moisture, high temperature)
- Mint harvest batches as ERC-721 NFTs on Polygon Amoy
- Each batch gets a unique QR code for product packaging
- Consumers can scan QR codes to verify authenticity on-chain
- Immutable record of: crop type, planting date, farm location, organic status
- Real MetaMask integration for signing blockchain transactions
- Smart farming assistant powered by Google Gemini 2.5 Flash
- Supports 8+ Indian languages: Hindi, Tamil, Telugu, Kannada, Malayalam, Bengali, Marathi, Gujarati
- Context-aware answers using real sensor data from your farm
- Intelligent fallback responses when API is unavailable
- Voice-like conversational interface
- Automatic pump activation when soil moisture drops below threshold
- Manual override from the dashboard
- Irrigation history and water usage logs
- Configurable thresholds per zone
- Weather Forecasting โ 3-day forecast with farming recommendations
- Crop Recommendations โ AI-suggested crops based on current conditions
- Multi-Zone Support โ Manage different areas of your farm
- Mobile-Responsive Design โ Full functionality on all devices
- Dark Mode โ Easy on the eyes for night monitoring
| Category | Technology |
|---|---|
| Frontend | Next.js 15, React 19, TailwindCSS, Shadcn UI, Framer Motion |
| Backend | Next.js API Routes, Supabase (PostgreSQL + RLS) |
| Blockchain | Polygon Amoy Testnet, Solidity 0.8.20, ethers.js v6, MetaMask |
| Smart Contract | ERC-721 (OpenZeppelin), Hardhat |
| AI/ML | Google Gemini 2.5 Flash API |
| IoT | ESP32 DevKit, DHT22 Sensor, Capacitive Soil Moisture Sensor |
| Charts | Recharts |
| QR Codes | qrcode (npm), browser-native scanning |
- Node.js 18+ and npm
- Supabase account (free tier works)
- Google Gemini API key (free tier: 15 RPM)
- MetaMask wallet (for blockchain features)
- ESP32 + Sensors (optional, for IoT features)
# Clone the repository
git clone https://github.com/Devvaibhavpk/Agroflow.git
cd Agroflow
# Install dependencies
npm install
# Copy environment template
cp .env.local.example .env.local
# Start development server
npm run devCreate .env.local with these values:
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# REQUIRED
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Supabase Database
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key_here
# Google Gemini AI (for chatbot)
GEMINI_API_KEY=your_gemini_api_key
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# BLOCKCHAIN (Pre-configured for demo)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
NEXT_PUBLIC_NFT_CONTRACT_ADDRESS=0x8e205B621E7D122C8B1FD2695080A5Ea31280709
NEXT_PUBLIC_POLYGON_RPC_URL=https://rpc-amoy.polygon.technology
NEXT_PUBLIC_CHAIN_ID=80002Run these SQL scripts in Supabase SQL Editor (in order):
supabase/setup.sqlโ Core tables (sensor_data, zones, users)supabase/blockchain_tables.sqlโ Harvest batches, blockchain logssupabase/fix_rls.sqlโ Relaxed RLS for demo modeโ ๏ธ supabase/sample_data.sqlโ Optional demo data
The AgroflowNFT contract is live on Polygon Amoy Testnet:
| Property | Value |
|---|---|
| Contract Address | 0x8e205B621E7D122C8B1FD2695080A5Ea31280709 |
| Network | Polygon Amoy (Chain ID: 80002) |
| Token Symbol | AGRO |
| Token Standard | ERC-721 |
| Explorer | View on PolygonScan |
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ 1. Create โ โ โ 2. Generate โ โ โ 3. Mint โ โ โ 4. Verify โ
โ Batch โ โ QR Code โ โ NFT โ โ on Chain โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
Farmer logs Unique ID MetaMask Consumer
harvest data assigned signs tx scans QR
// Mint a new harvest batch NFT
function mintBatch(address to, string qrCodeId, bytes32 dataHash, string uri) โ uint256
// Look up token by QR code
function getTokenByQrCode(string qrCodeId) โ uint256
// Verify data integrity
function verifyIntegrity(uint256 tokenId, bytes32 dataHash) โ bool
// Get batch details
function getBatchInfo(uint256 tokenId) โ (owner, qrCodeId, dataHash, uri)See contracts/DEPLOYMENT.md for step-by-step instructions using Hardhat or Remix.
| Endpoint | Method | Description |
|---|---|---|
/api/ask |
POST | AI chatbot with multilingual support |
/api/harvest |
GET | Fetch all harvest batches |
/api/harvest |
POST | Create new harvest batch |
/api/harvest |
PUT | Update batch / Mint as NFT |
/api/verify?qr_code_id=XX |
GET | Public verification endpoint |
/api/weather |
GET | Weather forecast data |
/api/recommendations |
GET | AI crop recommendations |
/api/nft-metadata/[qrCodeId] |
GET | NFT metadata (for OpenSea) |
curl -X POST http://localhost:3000/api/ask \
-H "Content-Type: application/json" \
-d '{
"question": "เคฎเฅเคฐเฅ เคซเคธเคฒ เคเฅ เคฒเคฟเค เคธเคฌเคธเฅ เค
เคเฅเคเคพ เคธเคฎเคฏ เคเฅเคฏเคพ เคนเฅ?",
"language": "hindi"
}'curl -X POST http://localhost:3000/api/harvest \
-H "Content-Type: application/json" \
-d '{
"cropName": "Tomato",
"cropVariety": "Roma",
"plantingDate": "2026-01-15",
"farmLocation": "Chennai, Tamil Nadu",
"isOrganic": true
}'| Component | Purpose | GPIO |
|---|---|---|
| ESP32 DevKit | Main controller | - |
| DHT22 | Temperature & Humidity | GPIO 4 |
| Soil Moisture Sensor | Soil monitoring | GPIO 34 (ADC) |
| 5V Relay Module | Pump control | GPIO 26 |
| Water Pump | Irrigation | Via Relay |
ESP32 Sensors
โโโโโ โโโโโโโ
GPIO 4 โโโโโโโโโโโโโโโโ DHT22 Data
GPIO 34 โโโโโโโโโโโโโโโโ Moisture Sensor (Analog)
GPIO 26 โโโโโโโโโโโโโโโโ Relay IN (Pump Control)
3.3V โโโโโโโโโโโโโโโโ DHT22 VCC
5V โโโโโโโโโโโโโโโโ Relay VCC, Moisture VCC
GND โโโโโโโโโโโโโโโโ All GND
- Open
esp32/agroflow_firmware.inoin Arduino IDE - Install required libraries:
DHT sensor library,ArduinoJson,WiFi - Update credentials:
const char* ssid = "YOUR_WIFI_SSID"; const char* password = "YOUR_WIFI_PASSWORD"; const char* supabaseUrl = "https://your-project.supabase.co"; const char* supabaseKey = "your_anon_key";
- Upload to ESP32
- Open Serial Monitor (115200 baud) to verify connection
See esp32/README.md for detailed troubleshooting.
Agroflow/
โโโ app/ # Next.js App Router
โ โโโ api/ # API Routes
โ โ โโโ ask/ # AI Chatbot
โ โ โโโ harvest/ # Batch CRUD
โ โ โโโ verify/ # Public verification
โ โ โโโ nft-metadata/ # NFT metadata endpoint
โ โโโ dashboard/ # Main monitoring dashboard
โ โโโ traceability/ # NFT minting interface
โ โโโ verify/[qrCodeId]/ # Consumer verification page
โ โโโ chatbot/ # AI assistant page
โ โโโ settings/ # User preferences
โ โโโ docs/ # Documentation
โ โโโ about/ # About page
โโโ components/ # React components
โ โโโ WalletConnect.tsx # MetaMask integration
โ โโโ ui/ # Shadcn UI components
โโโ contracts/ # Solidity smart contracts
โ โโโ src/AgroflowNFT.sol # Main ERC-721 contract
โ โโโ scripts/deploy.js # Hardhat deploy script
โ โโโ DEPLOYMENT.md # Deployment guide
โโโ esp32/ # ESP32 Arduino firmware
โ โโโ agroflow_firmware.ino # Main firmware
โ โโโ README.md # Hardware setup guide
โโโ lib/ # Utility libraries
โ โโโ wallet.ts # MetaMask/blockchain utils
โ โโโ supabase.ts # Database client
โ โโโ blockchain.ts # Hash functions
โโโ supabase/ # Database scripts
โ โโโ setup.sql # Core tables
โ โโโ blockchain_tables.sql # NFT tables
โ โโโ fix_rls.sql # RLS policies
โ โโโ sample_data.sql # Demo data
โโโ public/ # Static assets
| Page | Description |
|---|---|
/ |
Landing page with feature overview |
/dashboard |
Real-time sensor monitoring |
/traceability |
Create batches & mint NFTs |
/chatbot |
AI farming assistant |
/verify/[qrCodeId] |
Consumer verification |
/docs |
API documentation |
- Get test MATIC from Polygon Faucet
- Connect MetaMask to Polygon Amoy
- Go to
/traceabilityโ Create batch โ Mint NFT - View your NFT on PolygonScan
We welcome contributions! Here's how:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is licensed under the MIT License โ see LICENSE for details.
Built with โค๏ธ for sustainable agriculture and transparent food supply chains.
Repository: github.com/Devvaibhavpk/Agroflow
๐ฑ Empowering Farmers โข Connecting Consumers โข Securing the Food Chain ๐ฑ
