Low-power ESP32-based environmental monitoring system for beehive health tracking. Collects temperature, humidity, CO2, vibration, and battery data every 15 minutes with deep sleep power management( expermental )
-
Multi-Sensor Data Collection
- BME680: Temperature, humidity, pressure, CO2 approximation
- DS3231 RTC: Accurate timestamping with battery backup
- Piezo sensor: Vibration frequency and amplitude detection
- Battery monitoring: Voltage level tracking
-
Power Optimized
- 15-minute wake/sleep cycles
- Active time: <30 seconds per cycle
-
Reliable Data Storage
- NVS-based persistent storage (survives power loss)
- Unlimited reading accumulation until transmission
- Automatic retry on write failures
- Batch JSON formatting for efficient transmission -implemented my json formater to enhace memory usage
-
WiFi Transmission (Placeholder)
- Batch upload when WiFi available
- Automatic NVS clearing after successful send
- Graceful degradation when offline
- Board: ESP32 WROVER
- Sensors:
- BME680 (I2C: 0x76)
- DS3231 RTC (I2C: 0x68)
- Piezo vibration sensor (ADC: GPIO36)
- Battery monitor (ADC: GPIO35)
- Power: 3.3V regulated, LiPo battery with voltage divider
┌─────────────────────────────────────────────────────┐
│ Application │
│ (main.c) │
└──────────────┬──────────────────────┬───────────────┘
│ │
┌───────▼────────┐ ┌────────▼────────┐
│ Services │ │ Services │
│ │ │ │
│ • Data Manager │ │ • Comm Manager │
│ • Power Manager│ │ │
└───────┬────────┘ └─────────────────┘
│
┌───────▼────────────────────────────────┐
│ Hardware Abstraction │
│ │
│ • BME680 • DS3231 • Vibration │
│ • Battery │
└───────────────────────────────────────┘
- HAL (Hardware Abstraction): Direct sensor communication, I2C/ADC drivers
- Services: Business logic, data persistence, power management
- Application: Sequential workflow orchestration
- PlatformIO installed
- ESP-IDF 5.0 or later
cd BeeHiveP
pio run -t upload
pio device monitorEdit include/config.h to customize:
// Timing
#define READING_INTERVAL_MIN 15 // Wake interval
#define TRANSMISSION_INTERVAL 4 // Readings before send
// WiFi (placeholder)
#define WIFI_SSID "YOUR_SSID"
#define WIFI_PASSWORD "YOUR_PASSWORD"
#define SERVER_URL "http://your-server/api/sensor-data"
// I2C Addresses
#define BME680_I2C_ADDR 0x76 // or 0x77
#define DS3231_I2C_ADDR 0x68- Wake from deep sleep (timer-based, 15 min default)
- Initialize sensors and services
- Read sensors (BME680, RTC, vibration, battery)
- Store reading in NVS flash
- Attempt transmission (WiFi connect → send JSON → clear NVS)
- Enter deep sleep (repeat)
JSON payload (minimal keys for bandwidth efficiency):
{
"id": "esp32_sensor_001",
"r": [
{
"ts": 1737820800,
"temp": 22.5,
"hum": 55.2,
"co2": 450,
"vib": 0.123,
"batt": 85
}
]
}- RAM: ~3KB (static buffers, no heap fragmentation)
- NVS: ~100 bytes per reading
- JSON Buffer: 2.8KB (temporary, freed after send)
BeeHiveP/
├── include/ # Public headers
│ ├── config.h # System-wide configuration
│ ├── datatypes.h # Shared data structures
│ └── *.h # Component interfaces
├── lib/
│ ├── hal/ # Hardware abstraction layer
│ │ ├── bme680/ # Environmental sensor
│ │ ├── ds3231/ # Real-time clock
│ │ ├── vibration/ # Piezo sensor
│ │ └── battery/ # Battery monitor
│ └── services/ # Business logic layer
│ ├── data_manager/ # NVS storage & JSON
│ ├── comm_manager/ # WiFi & HTTP (placeholder)
│ └── power_manager/ # Deep sleep control
├── src/
│ └── main.c # Application entry point
└── platformio.ini # Build configuration
Managed via ESP-IDF Component Registry (src/idf_component.yml):
esp-idf-lib/bme680^1.0.0esp-idf-lib/ds3231^1.0.0