Updated after completion of scheduler
This commit is contained in:
@ -4,14 +4,14 @@
|
|||||||
## Project Overview
|
## Project Overview
|
||||||
**Goal**: Automated plant watering system with remote monitoring/control
|
**Goal**: Automated plant watering system with remote monitoring/control
|
||||||
**Hardware**: ESP32-S3-MINI-1, TB6612FNG motor driver, 2 pumps, 2 soil moisture sensors
|
**Hardware**: ESP32-S3-MINI-1, TB6612FNG motor driver, 2 pumps, 2 soil moisture sensors
|
||||||
**Software**: ESP-IDF v6, MQTT communication, OTA updates
|
**Software**: ESP-IDF v6, MQTT communication, OTA updates, NTP time sync, Scheduling
|
||||||
**Infrastructure**: Docker-based Mosquitto MQTT broker, local network deployment
|
**Infrastructure**: Docker-based Mosquitto MQTT broker, local network deployment
|
||||||
|
|
||||||
## Project Status Summary
|
## Project Status Summary
|
||||||
- **Phase 1**: Core Infrastructure ✅ COMPLETED
|
- **Phase 1**: Core Infrastructure ✅ COMPLETED
|
||||||
- **Phase 2**: Hardware Integration 🚧 IN PROGRESS (Motor Control next)
|
- **Phase 2**: Hardware Integration 🚧 75% COMPLETE (Motors done, Sensors pending)
|
||||||
- **Phase 3**: Automation Logic 📋 TODO
|
- **Phase 3**: Automation Logic ✅ COMPLETED (via Scheduler)
|
||||||
- **Phase 4**: Enhanced Features 📋 TODO
|
- **Phase 4**: Enhanced Features 🚧 50% COMPLETE
|
||||||
- **Phase 5**: Production Polish 📋 TODO
|
- **Phase 5**: Production Polish 📋 TODO
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -41,108 +41,120 @@
|
|||||||
- Auto-reconnect with exponential backoff
|
- Auto-reconnect with exponential backoff
|
||||||
- Last Will and Testament
|
- Last Will and Testament
|
||||||
- NVS credential storage
|
- NVS credential storage
|
||||||
- Basic publish/subscribe implementation
|
- Comprehensive publish/subscribe implementation
|
||||||
- Current topics:
|
- Topics implemented:
|
||||||
- `plant_watering/status`
|
- `plant_watering/status`
|
||||||
- `plant_watering/moisture/[1-2]`
|
- `plant_watering/moisture/[1-2]`
|
||||||
- `plant_watering/pump/[1-2]/set`
|
- `plant_watering/pump/[1-2]/set`
|
||||||
- `plant_watering/pump/[1-2]/state`
|
- `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 🚧 IN PROGRESS
|
## Phase 2: Hardware Integration 🚧 75% COMPLETE
|
||||||
|
|
||||||
### 2.1 Motor Control Module 🚧 NEXT
|
### 2.1 Motor Control Module ✅ COMPLETED
|
||||||
**File**: `motor_control.c/h`
|
**Files**: `motor_control.c/h`
|
||||||
- [ ] TB6612FNG driver initialization
|
- TB6612FNG driver implementation ✅
|
||||||
- [ ] PWM control for pump speed
|
- PWM control for pump speed ✅
|
||||||
- [ ] Direction control (though pumps are unidirectional)
|
- Direction control ✅
|
||||||
- [ ] Safety features:
|
- Safety features:
|
||||||
- [ ] Maximum runtime limit (30 seconds default)
|
- Maximum runtime limit ✅
|
||||||
- [ ] Minimum interval between runs (5 minutes)
|
- Minimum interval between runs ✅
|
||||||
- [ ] Overcurrent detection (if possible)
|
- Soft start (500ms ramp) ✅
|
||||||
- [ ] Manual override commands via MQTT
|
- Emergency stop ✅
|
||||||
- [ ] State tracking and reporting
|
- Manual override via MQTT ✅
|
||||||
|
- State tracking and reporting ✅
|
||||||
|
- Runtime statistics with NVS persistence ✅
|
||||||
|
- Tested and working with hardware ✅
|
||||||
|
|
||||||
### 2.2 Moisture Sensor Module 📋 TODO
|
### 2.2 Moisture Sensor Module ⏸️ ON HOLD
|
||||||
**File**: `moisture_sensor.c/h`
|
**File**: `moisture_sensor.c/h`
|
||||||
- [ ] ADC configuration for 2 sensors
|
- [ ] ADC configuration for 2 sensors
|
||||||
- [ ] Calibration system:
|
- [ ] Calibration system
|
||||||
- [ ] Dry value calibration
|
- [ ] Reading stabilization
|
||||||
- [ ] Wet value calibration
|
|
||||||
- [ ] Store calibration in NVS
|
|
||||||
- [ ] Reading stabilization:
|
|
||||||
- [ ] Multiple sample averaging
|
|
||||||
- [ ] Outlier filtering
|
|
||||||
- [ ] Trend detection
|
|
||||||
- [ ] Percentage conversion
|
- [ ] Percentage conversion
|
||||||
- [ ] Sensor fault detection
|
- [ ] Sensor fault detection
|
||||||
|
**Note**: Awaiting hardware delivery
|
||||||
|
|
||||||
### 2.3 Hardware Integration Testing 📋 TODO
|
### 2.3 Hardware Integration Testing 🚧 PARTIAL
|
||||||
- [ ] Verify pump operation at different PWM levels
|
- [x] Pump operation verified
|
||||||
- [ ] Test moisture sensor accuracy
|
- [x] PWM speed control tested
|
||||||
- [ ] Validate power consumption
|
- [x] Safety features validated
|
||||||
- [ ] Long-term reliability testing (24-hour test)
|
- [ ] Moisture sensor integration (pending hardware)
|
||||||
|
- [ ] Full system integration test
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Phase 3: Automation Logic 📋 TODO
|
## Phase 3: Automation Logic ✅ COMPLETED (via Scheduler)
|
||||||
|
|
||||||
### 3.1 Basic Automation 📋 TODO
|
### 3.1 Time-Based Scheduling ✅ COMPLETED
|
||||||
**File**: `automation.c/h`
|
**Files**: `scheduler.c/h`
|
||||||
- [ ] Threshold-based watering:
|
- Multiple schedule types:
|
||||||
- [ ] Start when moisture < 30%
|
- Interval-based (every X minutes) ✅
|
||||||
- [ ] Stop when moisture > 70%
|
- Time of day (daily at specific time) ✅
|
||||||
- [ ] Safety checks:
|
- Day-specific (specific days at time) ✅
|
||||||
- [ ] Maximum daily watering limit
|
- Per-pump scheduling (4 schedules each) ✅
|
||||||
- [ ] Minimum interval enforcement
|
- NVS persistence ✅
|
||||||
- [ ] Pump runtime limits
|
- MQTT configuration ✅
|
||||||
- [ ] Zone independence (2 separate zones)
|
- Holiday mode ✅
|
||||||
|
- Manual trigger for testing ✅
|
||||||
|
|
||||||
### 3.2 Advanced Scheduling 📋 TODO
|
### 3.2 Time Synchronization ✅ COMPLETED
|
||||||
- [ ] Time-based watering schedules
|
- NTP client implementation ✅
|
||||||
- [ ] Dawn/dusk watering preferences
|
- Multiple NTP servers ✅
|
||||||
- [ ] Weekly patterns
|
- Manual time setting fallback ✅
|
||||||
- [ ] Seasonal adjustments
|
- Timezone support (MST default) ✅
|
||||||
|
- Time status reporting ✅
|
||||||
|
|
||||||
### 3.3 Data Logging 📋 TODO
|
### 3.3 Schedule Management ✅ COMPLETED
|
||||||
- [ ] Log watering events
|
- Create/update schedules via MQTT ✅
|
||||||
- [ ] Track moisture trends
|
- View all schedules on demand ✅
|
||||||
- [ ] Record pump runtime statistics
|
- Enable/disable without deletion ✅
|
||||||
- [ ] Store in NVS with rotation
|
- Execution notifications ✅
|
||||||
|
- Error reporting ✅
|
||||||
|
|
||||||
|
### 3.4 Moisture-Based Automation ⏸️ PENDING
|
||||||
|
- Awaiting sensor hardware
|
||||||
|
- Will integrate with scheduler when available
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Phase 4: Enhanced MQTT & Monitoring 📋 TODO
|
## Phase 4: Enhanced MQTT & Monitoring 🚧 50% COMPLETE
|
||||||
|
|
||||||
### 4.1 Expanded MQTT Topics 📋 TODO
|
### 4.1 Expanded MQTT Topics ✅ COMPLETED
|
||||||
Implement the comprehensive topic structure:
|
Comprehensive topic structure implemented:
|
||||||
```
|
```
|
||||||
plant_watering/
|
plant_watering/
|
||||||
├── status/esp32/*
|
├── status/esp32/*
|
||||||
├── pump/[1-2]/*
|
├── pump/[1-2]/*
|
||||||
├── sensor/[1-2]/*
|
├── schedule/*
|
||||||
|
├── system/*
|
||||||
├── settings/*
|
├── settings/*
|
||||||
├── alerts/*
|
├── alerts/*
|
||||||
└── commands/*
|
└── commands/*
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4.2 JSON Payloads 📋 TODO
|
### 4.2 JSON Payloads ✅ COMPLETED
|
||||||
- [ ] Structured data for complex messages
|
- Structured data for schedules ✅
|
||||||
- [ ] Batch updates for efficiency
|
- Status messages ✅
|
||||||
- [ ] Schema versioning
|
- Configuration updates ✅
|
||||||
|
- Built-in JSON parsing (no external deps) ✅
|
||||||
|
|
||||||
### 4.3 Alert System 📋 TODO
|
### 4.3 Alert System 🚧 PARTIAL
|
||||||
- [ ] Low moisture alerts
|
- [x] Pump malfunction alerts
|
||||||
- [ ] Pump malfunction detection
|
- [x] Schedule execution errors
|
||||||
- [ ] Sensor fault alerts
|
- [ ] Low moisture alerts (pending sensors)
|
||||||
- [ ] Water tank low (future)
|
- [ ] Water tank monitoring (future)
|
||||||
|
|
||||||
### 4.4 Remote Configuration 📋 TODO
|
### 4.4 Remote Configuration ✅ COMPLETED
|
||||||
- [ ] MQTT-based settings updates
|
- MQTT-based settings updates ✅
|
||||||
- [ ] Validation and bounds checking
|
- Validation and bounds checking ✅
|
||||||
- [ ] Persistent storage in NVS
|
- Persistent storage in NVS ✅
|
||||||
- [ ] Configuration backup/restore
|
- Runtime parameter changes ✅
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -152,7 +164,7 @@ plant_watering/
|
|||||||
- [ ] Real-time status display
|
- [ ] Real-time status display
|
||||||
- [ ] Historical graphs
|
- [ ] Historical graphs
|
||||||
- [ ] Manual control interface
|
- [ ] Manual control interface
|
||||||
- [ ] Configuration portal
|
- [ ] Schedule configuration UI
|
||||||
- [ ] Mobile-responsive design
|
- [ ] Mobile-responsive design
|
||||||
|
|
||||||
### 5.2 Home Assistant Integration 📋 TODO
|
### 5.2 Home Assistant Integration 📋 TODO
|
||||||
@ -168,108 +180,127 @@ plant_watering/
|
|||||||
- [ ] Predictive watering
|
- [ ] Predictive watering
|
||||||
- [ ] Water usage tracking
|
- [ ] Water usage tracking
|
||||||
|
|
||||||
### 5.4 Production Hardening 📋 TODO
|
### 5.4 Production Hardening 🚧 PARTIAL
|
||||||
- [ ] Watchdog timer implementation
|
- [x] Watchdog timer (system level)
|
||||||
- [ ] Brown-out detection
|
- [ ] Enhanced error recovery
|
||||||
- [ ] Error recovery procedures
|
|
||||||
- [ ] Factory reset mechanism
|
- [ ] Factory reset mechanism
|
||||||
- [ ] Diagnostic mode
|
- [ ] 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)
|
## Hardware Connections (Reference)
|
||||||
|
|
||||||
### ESP32-S3 to TB6612FNG
|
### ESP32-S3 to TB6612FNG ✅ VERIFIED
|
||||||
```
|
```
|
||||||
ESP32-S3 TB6612FNG
|
ESP32-S3 TB6612FNG Status
|
||||||
GPIO4 -> AIN1 (Pump 1 Direction)
|
GPIO4 -> AIN1 ✅ Working
|
||||||
GPIO5 -> AIN2 (Pump 1 Direction)
|
GPIO5 -> AIN2 ✅ Working
|
||||||
GPIO6 -> BIN1 (Pump 2 Direction)
|
GPIO6 -> BIN1 ✅ Working
|
||||||
GPIO7 -> BIN2 (Pump 2 Direction)
|
GPIO7 -> BIN2 ✅ Working
|
||||||
GPIO8 -> PWMA (Pump 1 Speed)
|
GPIO8 -> PWMA ✅ Working
|
||||||
GPIO9 -> PWMB (Pump 2 Speed)
|
GPIO9 -> PWMB ✅ Working
|
||||||
GPIO10 -> STBY (Standby)
|
GPIO10 -> STBY ✅ Working
|
||||||
GND -> GND
|
GND -> GND ✅ Connected
|
||||||
3.3V -> VCC
|
3.3V -> VCC ✅ Connected
|
||||||
```
|
```
|
||||||
|
|
||||||
### Moisture Sensors
|
### Moisture Sensors ⏸️ PENDING
|
||||||
```
|
```
|
||||||
Sensor 1 -> GPIO1 (ADC1_CHANNEL_0)
|
Sensor 1 -> GPIO1 (ADC1_CHANNEL_0) - Awaiting hardware
|
||||||
Sensor 2 -> GPIO2 (ADC1_CHANNEL_1)
|
Sensor 2 -> GPIO2 (ADC1_CHANNEL_1) - Awaiting hardware
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Development Guidelines
|
## Next Steps
|
||||||
|
|
||||||
### Commit Strategy
|
### Immediate (This Week)
|
||||||
- Complete one module at a time
|
1. ✅ ~~Test interval scheduling mode~~
|
||||||
- Test thoroughly before moving to next module
|
2. ⏸️ Install moisture sensors when they arrive
|
||||||
- Tag releases for each completed phase
|
3. ✅ ~~Document all MQTT topics comprehensively~~
|
||||||
|
4. ⏸️ Create basic web dashboard mockup
|
||||||
|
|
||||||
### Testing Protocol
|
### Short Term (Next Month)
|
||||||
1. Unit test each module independently
|
1. Implement moisture sensor module
|
||||||
2. Integration test with MQTT broker
|
2. Integrate moisture readings with scheduler
|
||||||
3. Hardware-in-the-loop testing
|
3. Add moisture-based automation rules
|
||||||
4. 24-hour reliability test
|
4. Implement Home Assistant discovery
|
||||||
5. Edge case validation
|
|
||||||
|
|
||||||
### Documentation Requirements
|
### Long Term
|
||||||
- Update README with each feature
|
1. Multi-zone expansion (>2 pumps)
|
||||||
- Document MQTT topics as implemented
|
2. Weather API integration
|
||||||
- Include calibration procedures
|
3. Water usage analytics
|
||||||
- Add troubleshooting guides
|
4. Mobile app development
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Current Sprint Focus
|
|
||||||
**Sprint Goal**: Complete Phase 2 Hardware Integration
|
|
||||||
1. Implement motor_control.c ← **CURRENT**
|
|
||||||
2. Test with actual pumps
|
|
||||||
3. Implement moisture_sensor.c
|
|
||||||
4. Calibrate sensors
|
|
||||||
5. Integration testing
|
|
||||||
|
|
||||||
**Definition of Done**:
|
|
||||||
- Code compiles without warnings
|
|
||||||
- Hardware responds to MQTT commands
|
|
||||||
- Sensor readings are accurate and stable
|
|
||||||
- No memory leaks (monitor heap)
|
|
||||||
- Documentation updated
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Risk Mitigation
|
|
||||||
|
|
||||||
### Technical Risks
|
|
||||||
- **Power supply issues**: Add capacitors, monitor voltage
|
|
||||||
- **Sensor corrosion**: Use capacitive sensors, implement sleep modes
|
|
||||||
- **Network reliability**: Implement offline mode with local rules
|
|
||||||
- **Flash wear**: Minimize NVS writes, implement wear leveling
|
|
||||||
|
|
||||||
### Mitigation Strategies
|
|
||||||
- Implement watchdog timers
|
|
||||||
- Add redundant sensors
|
|
||||||
- Local automation fallback
|
|
||||||
- Comprehensive error logging
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Success Metrics
|
## Success Metrics
|
||||||
- ✅ Reliable WiFi/MQTT connectivity
|
- ✅ Reliable WiFi/MQTT connectivity (achieved)
|
||||||
- ⏳ Accurate moisture readings (±5%)
|
- ✅ Accurate time-based scheduling (achieved)
|
||||||
- ⏳ Precise watering control
|
- ✅ Precise watering control (achieved)
|
||||||
- ⏳ 30-day uptime without intervention
|
- ✅ OTA updates without service interruption (achieved)
|
||||||
- ⏳ < 100mA average power consumption
|
- ✅ Response time < 1 second for commands (achieved)
|
||||||
- ⏳ OTA updates without service interruption
|
- ⏳ Accurate moisture readings (±5%) - pending hardware
|
||||||
- ⏳ Response time < 1 second for commands
|
- ⏳ 30-day uptime without intervention - in progress
|
||||||
|
- ⏳ < 100mA average power consumption - to be measured
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Next Actions
|
## Known Issues
|
||||||
1. **Create motor_control.c/h** with TB6612FNG driver
|
1. None currently - system stable
|
||||||
2. **Wire up hardware** on breadboard
|
|
||||||
3. **Test pump control** via MQTT commands
|
## Risk Mitigation
|
||||||
4. **Implement safety features** (timeouts, limits)
|
- ✅ Implemented watchdog timers
|
||||||
5. **Document findings** and update plan
|
- ✅ 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
|
||||||
Reference in New Issue
Block a user