IoT Plant and Environment Monitor
A complete IoT system for monitoring home environment and plant moisture levels, hosted at crabdance.milescb.com. The project combines embedded systems, web development, and backend services to create a real-time monitoring solution running on a Raspberry Pi Zero 2W with ESP8266-based sensor nodes.
Motivation
Home plant care and environmental monitoring require consistent attention and manual measurement. This project automates the monitoring process, providing real-time data visualization and historical tracking accessible from anywhere via the web. The system demonstrates practical applications of IoT architecture, including sensor networks, message queuing protocols, database management, and web service deployment.
System Architecture
Hardware Components
Raspberry Pi Zero 2W Server:
- Hosts the website using nginx web server
- Runs Flask-based REST API for database queries (served via Gunicorn)
- Manages MQTT broker for sensor data collection
- Stores historical data in SQLite database
ESP8266 Sensor Nodes:
- DHT sensor for temperature and humidity measurements
- CD4051BE multiplexer with capacitive moisture sensors
- WiFi connectivity for MQTT message publishing
- Custom Arduino library (PlantMonitor) for sensor integration
Software Stack
Frontend:
- Responsive web interface
- Real-time data visualization using JavaScript
- Chart.js for moisture history graphs
- Mobile-friendly design
Backend:
- Python services for MQTT subscription and database management
- Gunicorn server for API endpoints
- SQLite database for efficient time-series data storage
- systemd integration for reliable service management
Networking:
- nginx reverse proxy for secure HTTPS traffic
- Cloudflare Tunnel for secure external access without port forwarding
- SSL/TLS certificates via Let’s Encrypt (for non-Cloudflare deployments)
- MQTT protocol for lightweight sensor communication
Technical Implementation
Sensor Network
The ESP8266 nodes use the custom PlantMonitor library to interface with multiple sensors:
- Analog multiplexing: CD4051BE allows reading up to 8 capacitive moisture sensors through a single analog input
- Address selection: Three digital GPIO pins control which sensor is actively being read
- Calibration system: Configurable wet/dry thresholds for accurate moisture percentage calculation
- MQTT publishing: Periodic transmission of sensor readings to the central broker
Data Pipeline
- Data Collection: ESP8266 sensors publish readings to MQTT topics
- Data Ingestion: Python subscriber service listens to MQTT broker and writes to SQLite
- Data Storage: Time-series data stored with timestamps and sensor identifiers
- Data Retrieval: REST API queries database and serves JSON responses
- Data Visualization: Frontend JavaScript fetches API data and renders charts/displays
Deployment Configuration
The system supports two deployment options:
Free Domain with Port Forwarding:
- Uses FreeDNS for free subdomain registration
- Forwards ports 80 and 443 on home router
- Configures nginx with SSL certificates from certbot
- Includes security hardening (fail2ban, ufw firewall)
Cloudflare Tunnel (Recommended):
- Purchases domain through Cloudflare registrar
- Sets up Cloudflare Tunnel on Raspberry Pi
- Eliminates need for port forwarding
- Provides DDoS protection and enhanced security
Key Features
- Real-time Monitoring: Live temperature, humidity, and plant moisture levels
- Historical Data: Track environmental trends over time with interactive charts
- Multi-plant Support: Configure and monitor multiple plants simultaneously
- Responsive Design: Optimized for desktop and mobile viewing
- Theme Support: Light and dark mode for comfortable viewing
- Low Power: Efficient ESP8266 nodes with configurable sleep modes
- Modular Architecture: Easy to add new sensors or modify plant configurations