Intelligent Agricultural IoT System with AI Analysis & Blockchain Verification
A comprehensive smart farming platform combining IoT sensor data collection, AI-powered analysis, and blockchain-based data verification for sustainable agriculture.
- Overview
- Key Features
- System Architecture
- Installation
- Configuration
- Running Services
- API Documentation
- Testing
- Deployment
Pione AI-Blockchain-IoT is an end-to-end agricultural intelligence platform that:
- Collects 11 soil & weather parameters from IoT sensors (ESP8266/ESP32)
- Analyzes data using 4 ML models + Google Gemini AI (LLM WITH FACT mode)
- Stores immutable records on Zeroscan blockchain
- Provides real-time dashboard with crop recommendations & soil health insights
- Supports multi-method authentication (Passkey, PIN, Zalo integration)
✅ Precision Farming - Real-time soil monitoring & irrigation optimization ✅ Crop Planning - AI-powered crop recommendations based on soil conditions ✅ Data Transparency - Blockchain-verified audit trail for agricultural data ✅ Farmer Support - Natural language AI chatbot for agricultural advice ✅ Compliance - Immutable records for certification & traceability
- Soil Health Scoring (0-100 scale)
- Crop Recommendations - Predicts best crops for current conditions
- Anomaly Detection - Identifies unusual soil patterns
- LLM WITH FACT - Gemini AI responds only based on real database data (no hallucination)
- Natural Language Chat - Vietnamese language support with fallback rule-based AI
- Immutable Records - All sensor data hashed and anchored on Zeroscan
- Daily Insights - Aggregated AI analysis stored on-chain
- Duplicate Prevention - Prevents duplicate blockchain transactions
- Public Verification - Data verifiable via Zeroscan explorer
- Passkey (WebAuthn) - Biometric/PIN authentication on device
- PIN-Based - Traditional PIN authentication with bcrypt hashing
- Zalo Integration - Link Zalo account for notifications
- Live Sensor Data - 11 parameters updated in real-time
- 24-Hour Trends - Historical data visualization
- AI Insights History - Daily analysis records with blockchain status
- Crop Management - Track planted crops and harvest dates
- Responsive Design - Works on desktop, tablet, and mobile
IoT Sensors (ESP8266/ESP32)
↓ POST 11 parameters
Flask API (unified_backend.py:8080)
├─ Data Ingest
├─ Authentication
├─ AI Chat (LLM WITH FACT)
└─ Daily Analysis
↓
PostgreSQL (36.50.134.107:6000)
├─ sensor_readings
├─ daily_insights
├─ users
└─ ai_recommendations
↓
Node.js Bridge (server.js:3000)
↓ Blockchain callback
Smart Contract (SoilDataStore.sol)
↓ Zeroscan blockchain
Frontend (Next.js:3001)
├─ Dashboard
├─ AI Chat Modal
└─ Blockchain Verification
Soil (8): Temperature, Moisture, Conductivity, pH, N, P, K, Salinity Air (3): Temperature, Humidity, Rain Status
| Layer | Technology |
|---|---|
| Backend | Python (Flask, FastAPI), Node.js (Express) |
| Frontend | Next.js 15.1.2, React 19, TypeScript, Tailwind CSS |
| Database | PostgreSQL 12+ |
| AI/ML | TensorFlow, Scikit-learn, Google Gemini |
| Blockchain | Solidity 0.8.20, Ethers.js, Zeroscan |
| Auth | WebAuthn (Passkey), bcrypt, JWT |
- Node.js 18+, npm
- Python 3.10+
- PostgreSQL 12+
- Git
git clone https://github.com/WAGTeam/Pione_AIBlockchainIoT-WAGTeam.git
cd Pione_AIBlockchainIoT-WAGTeam
# Install all dependencies
npm install
pip install -r requirements.txt
cd ai_service && pip install -r requirements.txt && cd ..
cd Dapp/frontend && npm install && cd ../..# Database
PGHOST=your_database_host
PGPORT=5432
PGDATABASE=your_database_name
PGUSER=your_db_user
PGPASSWORD=your_secure_password
# Blockchain
RPC_URL=https://rpc.zeroscan.org
PRIVATE_KEY=0xyour_private_key_here
CONTRACT_ADDRESS=0xyour_contract_address
# AI Services
GEMINI_API_KEY=your_gemini_api_key_here
GEMINI_MODEL_NAME=gemini-2.5-pro
# Services
NODE_BRIDGE_URL=http://127.0.0.1:3000/bridgePendingpsql -h $PGHOST -U $PGUSER -d postgres -c "CREATE DATABASE $PGDATABASE;"
psql -h $PGHOST -U $PGUSER -d $PGDATABASE -f db.sql
psql -h $PGHOST -U $PGUSER -d $PGDATABASE -f migrations/*.sqlchmod +x START_UNIFIED.sh
./START_UNIFIED.shStarts all services:
- Backend API (Port 8080)
- Blockchain Bridge (Port 3000)
- AI Service (Port 8000)
- Frontend (Port 3001)
# Terminal 1: Backend
python unified_backend.py
# Terminal 2: Blockchain Bridge
node server.js
# Terminal 3: AI Service
cd ai_service && python main.py
# Terminal 4: Frontend
cd Dapp/frontend && npm run devcurl http://localhost:8080/api/latest
curl http://localhost:8000/api/ai/health
curl http://localhost:3000/status
open http://localhost:3001POST /api/data - Receive sensor data
curl -X POST http://localhost:8080/api/data \
-H "Content-Type: application/json" \
-d '{
"soil_temperature_c": 24.5,
"soil_moisture_pct": 45.2,
"conductivity_us_cm": 1250,
"ph_value": 6.8,
"nitrogen_mg_kg": 45,
"phosphorus_mg_kg": 30,
"potassium_mg_kg": 180,
"salt_mg_l": 850,
"air_temperature_c": 27.1,
"air_humidity_pct": 65.0,
"is_raining": false
}'POST /api/ai/chat - AI chatbot (LLM WITH FACT mode)
curl -X POST http://localhost:8080/api/ai/chat \
-H "Content-Type: application/json" \
-d '{"message": "Nhiệt độ + NPK ổn không?"}'POST /api/ai/analyze-daily-insights - Daily analysis + DB save + blockchain push
curl -X POST http://localhost:8080/api/ai/analyze-daily-insights \
-H "Content-Type: application/json" \
-d '{"date": "2025-11-10"}'GET /api/dashboard/overview - Statistics overview
curl http://localhost:8080/api/dashboard/overview# Test data ingest
curl -X POST http://localhost:8080/api/data \
-H "Content-Type: application/json" \
-d '{"soil_temperature_c": 24.5, ...}'
# Test AI chat
curl -X POST http://localhost:8080/api/ai/chat \
-H "Content-Type: application/json" \
-d '{"message": "Bón phân gì?"}'
# Check blockchain
curl http://localhost:3000/api/getPendingdocker-compose build
docker-compose up -d
docker-compose logs -f- Strong database passwords
- HTTPS/SSL certificates
- Secure environment variables
- Database backups enabled
- Firewall rules configured
- Monitoring & alerting setup
- Rate limiting enabled
- CORS properly configured
- Log aggregation setup
- Disaster recovery tested
- Fork repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
MIT License - see LICENSE file for details
Version: 2.0.0 | Last Updated: November 2025