How heuscartist/smart-agriculture-dashboard works
Project Type and Purpose
• This is a full-stack IoT data engineering pipeline for smart agriculture:
• Hardware layer: ESP32 sensor node (temperature, humidity, soil moisture) and ESP32-CAM.
• Ingestion & API layer: Flask-based API for sensor data (real or simulated).
• Time-series storage: InfluxDB.
• Processing layer: Python scripts (influx_writer.py, fetch_image.py) and PyTorch model for plant-health classification.
• Visualization: Streamlit dashboard (app.py).
Main Components
a. Hardware
• ESP32 Sensor Node (sensors.ino)
• ESP32-CAM Node (camera.ino, handlers.cpp, WifiCam.hpp)
b. Network / Transport
• Wi-Fi network
• HTTP endpoints (Flask API for sensor data; ESP32-CAM HTTP server for images)
c. Ingestion & API
• sensor_simulator.py (Flask server to simulate or relay ESP32 sensor data)
• influx_writer.py (polls Flask API every 5s → writes JSON data to InfluxDB)
d. Storage
• InfluxDB (bucket “esp32_data”) for time-series sensor readings
• Local filesystem (data/latest.jpg) for the latest plant image
• model/plant_classifier.pth (PyTorch ResNet18 binary)
e. Processing
• fetch_image.py (downloads current image from ESP32-CAM → saves to data/)
• PyTorch inference (load ResNet18 model → classify data/latest.jpg)
f. Visualization
• app.py (Streamlit): queries InfluxDB for sensor metrics; loads latest.jpg; applies model; renders charts, image, health prediction
Relationships & Data Flow
1. ESP32 Sensor Node → HTTP POST/GET → Flask API (sensor_simulator or real)
2. influx_writer.py → HTTP GET → Flask API → InfluxDB write
3. ESP32-CAM → HTTP GET → fetch_image.py → data/latest.jpg
4. app.py:
• Reads sensor time-series from InfluxDB
• Reads data/latest.jpg
• Runs PyTorch model inference
• Renders Streamlit UI → browser
5. User interacts via browser → Streamlit app
Architectural Patterns & Principles
• Separation of concerns: hardware, ingestion, storage, processing, presentation
• Modular pipeline: independent scripts/services linked by HTTP & DB
• Microservice-style endpoints (Flask)
• Event-driven polling vs. push model
• Use of specialized stores: time-series DB for metrics; file system for images; model artifact store
Technologies & Libraries
• Embedded C++: ESP32, ESP32-CAM firmware
• Python:
• flask (sensor API)
• influxdb-client (DB writes & queries)
• requests (HTTP fetch)
• torch, torchvision, PIL (model inference)
• streamlit (dashboard)
• pandas, numpy (data manipulation)
• InfluxDB (time-series storage)
• PyTorch (ResNet18 binary classification)
Final Checklist
• [ ] All components labeled (firmware, scripts, DB, model, UI)
• [ ] Callouts for key design principles (modularity, separation, polling)