# ESP32-S3 Plant Watering System - Project Plan v2.0 *Updated: January 2025* ## Project Overview **Goal**: Automated plant watering system with remote monitoring/control **Hardware**: ESP32-S3-MINI-1, TB6612FNG motor driver, 2 pumps, 2 soil moisture sensors **Software**: ESP-IDF v6, MQTT communication, OTA updates, NTP time sync, Scheduling **Infrastructure**: Docker-based Mosquitto MQTT broker, local network deployment ## Project Status Summary - **Phase 1**: Core Infrastructure βœ… COMPLETED - **Phase 2**: Hardware Integration 🚧 75% COMPLETE (Motors done, Sensors pending) - **Phase 3**: Automation Logic βœ… COMPLETED (via Scheduler) - **Phase 4**: Enhanced Features 🚧 50% COMPLETE - **Phase 5**: Production Polish πŸ“‹ TODO --- ## Phase 1: Core Infrastructure βœ… COMPLETED ### 1.1 Development Environment βœ… - ESP-IDF v6 in Docker container - Build system configured - Project structure created ### 1.2 WiFi Manager βœ… - Auto-connect to configured network - Credential storage in NVS - Auto-reconnection on disconnect - Event callbacks for state changes ### 1.3 OTA Server βœ… - HTTP server on port 80 - Web interface for firmware upload - Progress tracking - Version management - Rollback capability ### 1.4 MQTT Client βœ… - Connection with authentication - Auto-reconnect with exponential backoff - Last Will and Testament - NVS credential storage - Comprehensive publish/subscribe implementation - Topics implemented: - `plant_watering/status` - `plant_watering/moisture/[1-2]` - `plant_watering/pump/[1-2]/set` - `plant_watering/pump/[1-2]/state` - `plant_watering/pump/[1-2]/speed` - `plant_watering/schedule/*` - `plant_watering/system/*` - `plant_watering/commands/*` --- ## Phase 2: Hardware Integration 🚧 75% COMPLETE ### 2.1 Motor Control Module βœ… COMPLETED **Files**: `motor_control.c/h` - TB6612FNG driver implementation βœ… - PWM control for pump speed βœ… - Direction control βœ… - Safety features: - Maximum runtime limit βœ… - Minimum interval between runs βœ… - Soft start (500ms ramp) βœ… - Emergency stop βœ… - Manual override via MQTT βœ… - State tracking and reporting βœ… - Runtime statistics with NVS persistence βœ… - Tested and working with hardware βœ… ### 2.2 Moisture Sensor Module ⏸️ ON HOLD **File**: `moisture_sensor.c/h` - [ ] ADC configuration for 2 sensors - [ ] Calibration system - [ ] Reading stabilization - [ ] Percentage conversion - [ ] Sensor fault detection **Note**: Awaiting hardware delivery ### 2.3 Hardware Integration Testing 🚧 PARTIAL - [x] Pump operation verified - [x] PWM speed control tested - [x] Safety features validated - [ ] Moisture sensor integration (pending hardware) - [ ] Full system integration test --- ## Phase 3: Automation Logic βœ… COMPLETED (via Scheduler) ### 3.1 Time-Based Scheduling βœ… COMPLETED **Files**: `scheduler.c/h` - Multiple schedule types: - Interval-based (every X minutes) βœ… - Time of day (daily at specific time) βœ… - Day-specific (specific days at time) βœ… - Per-pump scheduling (4 schedules each) βœ… - NVS persistence βœ… - MQTT configuration βœ… - Holiday mode βœ… - Manual trigger for testing βœ… ### 3.2 Time Synchronization βœ… COMPLETED - NTP client implementation βœ… - Multiple NTP servers βœ… - Manual time setting fallback βœ… - Timezone support (MST default) βœ… - Time status reporting βœ… ### 3.3 Schedule Management βœ… COMPLETED - Create/update schedules via MQTT βœ… - View all schedules on demand βœ… - Enable/disable without deletion βœ… - Execution notifications βœ… - Error reporting βœ… ### 3.4 Moisture-Based Automation ⏸️ PENDING - Awaiting sensor hardware - Will integrate with scheduler when available --- ## Phase 4: Enhanced MQTT & Monitoring 🚧 50% COMPLETE ### 4.1 Expanded MQTT Topics βœ… COMPLETED Comprehensive topic structure implemented: ``` plant_watering/ β”œβ”€β”€ status/esp32/* β”œβ”€β”€ pump/[1-2]/* β”œβ”€β”€ schedule/* β”œβ”€β”€ system/* β”œβ”€β”€ settings/* β”œβ”€β”€ alerts/* └── commands/* ``` ### 4.2 JSON Payloads βœ… COMPLETED - Structured data for schedules βœ… - Status messages βœ… - Configuration updates βœ… - Built-in JSON parsing (no external deps) βœ… ### 4.3 Alert System 🚧 PARTIAL - [x] Pump malfunction alerts - [x] Schedule execution errors - [ ] Low moisture alerts (pending sensors) - [ ] Water tank monitoring (future) ### 4.4 Remote Configuration βœ… COMPLETED - MQTT-based settings updates βœ… - Validation and bounds checking βœ… - Persistent storage in NVS βœ… - Runtime parameter changes βœ… --- ## Phase 5: Production Features πŸ“‹ TODO ### 5.1 Web Dashboard πŸ“‹ TODO - [ ] Real-time status display - [ ] Historical graphs - [ ] Manual control interface - [ ] Schedule configuration UI - [ ] Mobile-responsive design ### 5.2 Home Assistant Integration πŸ“‹ TODO - [ ] MQTT Discovery implementation - [ ] Device registry - [ ] Entity configuration - [ ] Automation examples ### 5.3 Advanced Features πŸ“‹ TODO - [ ] Multi-zone support (>2 zones) - [ ] Flow sensor integration - [ ] Weather API integration - [ ] Predictive watering - [ ] Water usage tracking ### 5.4 Production Hardening 🚧 PARTIAL - [x] Watchdog timer (system level) - [ ] Enhanced error recovery - [ ] Factory reset mechanism - [ ] Diagnostic mode - [x] Memory monitoring --- ## Current Capabilities ### Working Features 1. **Remote Control**: Full MQTT control of pumps 2. **Scheduling**: Time-based watering with multiple schedule types 3. **Safety**: Runtime limits, cooldown periods, emergency stop 4. **Monitoring**: Real-time status, statistics, time sync status 5. **OTA Updates**: Web-based firmware updates 6. **Persistence**: Settings and schedules survive reboots 7. **Time Management**: NTP sync with manual fallback ### Tested and Verified - Motor control with PWM speed adjustment - Schedule execution (time_of_day and days_time modes) - MQTT command processing - Safety features (max runtime, min interval) - OTA firmware updates - NVS persistence - Time synchronization --- ## Hardware Connections (Reference) ### ESP32-S3 to TB6612FNG βœ… VERIFIED ``` ESP32-S3 TB6612FNG Status GPIO4 -> AIN1 βœ… Working GPIO5 -> AIN2 βœ… Working GPIO6 -> BIN1 βœ… Working GPIO7 -> BIN2 βœ… Working GPIO8 -> PWMA βœ… Working GPIO9 -> PWMB βœ… Working GPIO10 -> STBY βœ… Working GND -> GND βœ… Connected 3.3V -> VCC βœ… Connected ``` ### Moisture Sensors ⏸️ PENDING ``` Sensor 1 -> GPIO1 (ADC1_CHANNEL_0) - Awaiting hardware Sensor 2 -> GPIO2 (ADC1_CHANNEL_1) - Awaiting hardware ``` --- ## Next Steps ### Immediate (This Week) 1. βœ… ~~Test interval scheduling mode~~ 2. ⏸️ Install moisture sensors when they arrive 3. βœ… ~~Document all MQTT topics comprehensively~~ 4. ⏸️ Create basic web dashboard mockup ### Short Term (Next Month) 1. Implement moisture sensor module 2. Integrate moisture readings with scheduler 3. Add moisture-based automation rules 4. Implement Home Assistant discovery ### Long Term 1. Multi-zone expansion (>2 pumps) 2. Weather API integration 3. Water usage analytics 4. Mobile app development --- ## Success Metrics - βœ… Reliable WiFi/MQTT connectivity (achieved) - βœ… Accurate time-based scheduling (achieved) - βœ… Precise watering control (achieved) - βœ… OTA updates without service interruption (achieved) - βœ… Response time < 1 second for commands (achieved) - ⏳ Accurate moisture readings (Β±5%) - pending hardware - ⏳ 30-day uptime without intervention - in progress - ⏳ < 100mA average power consumption - to be measured --- ## Known Issues 1. None currently - system stable ## Risk Mitigation - βœ… Implemented watchdog timers - βœ… Added redundant safety checks - βœ… Local schedule storage (survives network loss) - βœ… Comprehensive error logging - ⏸️ Sensor corrosion prevention (pending hardware) --- ## Version History - **v2.2.0-scheduler**: Full scheduling system with NTP - **v2.1.0-motor**: Motor control implementation - **v2.0.0-mqtt**: MQTT integration - **v1.0.1**: OTA-enabled base - **v1.0.0**: Initial template --- ## Documentation Status - βœ… README.md - Comprehensive project overview - βœ… MOTOR_CONTROL_README.md - Motor control details - βœ… SCHEDULER_README.md - Scheduling system guide - ⏸️ MQTT_TOPICS.md - To be created - ⏸️ API_REFERENCE.md - To be created --- ## Notes - Scheduler tested with days_time mode - working correctly - Time sync typically completes within 30 seconds of boot - System handles DST transitions automatically - All safety features have been validated with hardware