Updated after completion of scheduler
This commit is contained in:
@ -4,14 +4,14 @@
|
||||
## 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
|
||||
**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 🚧 IN PROGRESS (Motor Control next)
|
||||
- **Phase 3**: Automation Logic 📋 TODO
|
||||
- **Phase 4**: Enhanced Features 📋 TODO
|
||||
- **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
|
||||
|
||||
---
|
||||
@ -41,108 +41,120 @@
|
||||
- Auto-reconnect with exponential backoff
|
||||
- Last Will and Testament
|
||||
- NVS credential storage
|
||||
- Basic publish/subscribe implementation
|
||||
- Current topics:
|
||||
- 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 🚧 IN PROGRESS
|
||||
## Phase 2: Hardware Integration 🚧 75% COMPLETE
|
||||
|
||||
### 2.1 Motor Control Module 🚧 NEXT
|
||||
**File**: `motor_control.c/h`
|
||||
- [ ] TB6612FNG driver initialization
|
||||
- [ ] PWM control for pump speed
|
||||
- [ ] Direction control (though pumps are unidirectional)
|
||||
- [ ] Safety features:
|
||||
- [ ] Maximum runtime limit (30 seconds default)
|
||||
- [ ] Minimum interval between runs (5 minutes)
|
||||
- [ ] Overcurrent detection (if possible)
|
||||
- [ ] Manual override commands via MQTT
|
||||
- [ ] State tracking and reporting
|
||||
### 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 📋 TODO
|
||||
### 2.2 Moisture Sensor Module ⏸️ ON HOLD
|
||||
**File**: `moisture_sensor.c/h`
|
||||
- [ ] ADC configuration for 2 sensors
|
||||
- [ ] Calibration system:
|
||||
- [ ] Dry value calibration
|
||||
- [ ] Wet value calibration
|
||||
- [ ] Store calibration in NVS
|
||||
- [ ] Reading stabilization:
|
||||
- [ ] Multiple sample averaging
|
||||
- [ ] Outlier filtering
|
||||
- [ ] Trend detection
|
||||
- [ ] Calibration system
|
||||
- [ ] Reading stabilization
|
||||
- [ ] Percentage conversion
|
||||
- [ ] Sensor fault detection
|
||||
**Note**: Awaiting hardware delivery
|
||||
|
||||
### 2.3 Hardware Integration Testing 📋 TODO
|
||||
- [ ] Verify pump operation at different PWM levels
|
||||
- [ ] Test moisture sensor accuracy
|
||||
- [ ] Validate power consumption
|
||||
- [ ] Long-term reliability testing (24-hour test)
|
||||
### 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 📋 TODO
|
||||
## Phase 3: Automation Logic ✅ COMPLETED (via Scheduler)
|
||||
|
||||
### 3.1 Basic Automation 📋 TODO
|
||||
**File**: `automation.c/h`
|
||||
- [ ] Threshold-based watering:
|
||||
- [ ] Start when moisture < 30%
|
||||
- [ ] Stop when moisture > 70%
|
||||
- [ ] Safety checks:
|
||||
- [ ] Maximum daily watering limit
|
||||
- [ ] Minimum interval enforcement
|
||||
- [ ] Pump runtime limits
|
||||
- [ ] Zone independence (2 separate zones)
|
||||
### 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 Advanced Scheduling 📋 TODO
|
||||
- [ ] Time-based watering schedules
|
||||
- [ ] Dawn/dusk watering preferences
|
||||
- [ ] Weekly patterns
|
||||
- [ ] Seasonal adjustments
|
||||
### 3.2 Time Synchronization ✅ COMPLETED
|
||||
- NTP client implementation ✅
|
||||
- Multiple NTP servers ✅
|
||||
- Manual time setting fallback ✅
|
||||
- Timezone support (MST default) ✅
|
||||
- Time status reporting ✅
|
||||
|
||||
### 3.3 Data Logging 📋 TODO
|
||||
- [ ] Log watering events
|
||||
- [ ] Track moisture trends
|
||||
- [ ] Record pump runtime statistics
|
||||
- [ ] Store in NVS with rotation
|
||||
### 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 📋 TODO
|
||||
## Phase 4: Enhanced MQTT & Monitoring 🚧 50% COMPLETE
|
||||
|
||||
### 4.1 Expanded MQTT Topics 📋 TODO
|
||||
Implement the comprehensive topic structure:
|
||||
### 4.1 Expanded MQTT Topics ✅ COMPLETED
|
||||
Comprehensive topic structure implemented:
|
||||
```
|
||||
plant_watering/
|
||||
├── status/esp32/*
|
||||
├── pump/[1-2]/*
|
||||
├── sensor/[1-2]/*
|
||||
├── schedule/*
|
||||
├── system/*
|
||||
├── settings/*
|
||||
├── alerts/*
|
||||
└── commands/*
|
||||
```
|
||||
|
||||
### 4.2 JSON Payloads 📋 TODO
|
||||
- [ ] Structured data for complex messages
|
||||
- [ ] Batch updates for efficiency
|
||||
- [ ] Schema versioning
|
||||
### 4.2 JSON Payloads ✅ COMPLETED
|
||||
- Structured data for schedules ✅
|
||||
- Status messages ✅
|
||||
- Configuration updates ✅
|
||||
- Built-in JSON parsing (no external deps) ✅
|
||||
|
||||
### 4.3 Alert System 📋 TODO
|
||||
- [ ] Low moisture alerts
|
||||
- [ ] Pump malfunction detection
|
||||
- [ ] Sensor fault alerts
|
||||
- [ ] Water tank low (future)
|
||||
### 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 📋 TODO
|
||||
- [ ] MQTT-based settings updates
|
||||
- [ ] Validation and bounds checking
|
||||
- [ ] Persistent storage in NVS
|
||||
- [ ] Configuration backup/restore
|
||||
### 4.4 Remote Configuration ✅ COMPLETED
|
||||
- MQTT-based settings updates ✅
|
||||
- Validation and bounds checking ✅
|
||||
- Persistent storage in NVS ✅
|
||||
- Runtime parameter changes ✅
|
||||
|
||||
---
|
||||
|
||||
@ -152,7 +164,7 @@ plant_watering/
|
||||
- [ ] Real-time status display
|
||||
- [ ] Historical graphs
|
||||
- [ ] Manual control interface
|
||||
- [ ] Configuration portal
|
||||
- [ ] Schedule configuration UI
|
||||
- [ ] Mobile-responsive design
|
||||
|
||||
### 5.2 Home Assistant Integration 📋 TODO
|
||||
@ -168,108 +180,127 @@ plant_watering/
|
||||
- [ ] Predictive watering
|
||||
- [ ] Water usage tracking
|
||||
|
||||
### 5.4 Production Hardening 📋 TODO
|
||||
- [ ] Watchdog timer implementation
|
||||
- [ ] Brown-out detection
|
||||
- [ ] Error recovery procedures
|
||||
### 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
|
||||
### ESP32-S3 to TB6612FNG ✅ VERIFIED
|
||||
```
|
||||
ESP32-S3 TB6612FNG
|
||||
GPIO4 -> AIN1 (Pump 1 Direction)
|
||||
GPIO5 -> AIN2 (Pump 1 Direction)
|
||||
GPIO6 -> BIN1 (Pump 2 Direction)
|
||||
GPIO7 -> BIN2 (Pump 2 Direction)
|
||||
GPIO8 -> PWMA (Pump 1 Speed)
|
||||
GPIO9 -> PWMB (Pump 2 Speed)
|
||||
GPIO10 -> STBY (Standby)
|
||||
GND -> GND
|
||||
3.3V -> VCC
|
||||
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
|
||||
### Moisture Sensors ⏸️ PENDING
|
||||
```
|
||||
Sensor 1 -> GPIO1 (ADC1_CHANNEL_0)
|
||||
Sensor 2 -> GPIO2 (ADC1_CHANNEL_1)
|
||||
Sensor 1 -> GPIO1 (ADC1_CHANNEL_0) - Awaiting hardware
|
||||
Sensor 2 -> GPIO2 (ADC1_CHANNEL_1) - Awaiting hardware
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Development Guidelines
|
||||
## Next Steps
|
||||
|
||||
### Commit Strategy
|
||||
- Complete one module at a time
|
||||
- Test thoroughly before moving to next module
|
||||
- Tag releases for each completed phase
|
||||
### 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
|
||||
|
||||
### Testing Protocol
|
||||
1. Unit test each module independently
|
||||
2. Integration test with MQTT broker
|
||||
3. Hardware-in-the-loop testing
|
||||
4. 24-hour reliability test
|
||||
5. Edge case validation
|
||||
### 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
|
||||
|
||||
### Documentation Requirements
|
||||
- Update README with each feature
|
||||
- Document MQTT topics as implemented
|
||||
- Include calibration procedures
|
||||
- Add troubleshooting guides
|
||||
|
||||
---
|
||||
|
||||
## 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
|
||||
### 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
|
||||
- ⏳ Accurate moisture readings (±5%)
|
||||
- ⏳ Precise watering control
|
||||
- ⏳ 30-day uptime without intervention
|
||||
- ⏳ < 100mA average power consumption
|
||||
- ⏳ OTA updates without service interruption
|
||||
- ⏳ Response time < 1 second for commands
|
||||
- ✅ 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
|
||||
|
||||
---
|
||||
|
||||
## Next Actions
|
||||
1. **Create motor_control.c/h** with TB6612FNG driver
|
||||
2. **Wire up hardware** on breadboard
|
||||
3. **Test pump control** via MQTT commands
|
||||
4. **Implement safety features** (timeouts, limits)
|
||||
5. **Document findings** and update plan
|
||||
## 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
|
||||
Reference in New Issue
Block a user