- Issue: GPIO25 was used for both
TOUCH_SCLKandFLOW_METER_PIN, causing conflicts - Solution: Changed
FLOW_METER_PINfrom GPIO25 to GPIO26 - Impact: Flow meter and touch screen can now work simultaneously without conflicts
- Files Changed:
include/config.h: UpdatedFLOW_METER_PINdefinitiondocs/HARDWARE_SETUP.md: Updated pin documentationdocs/FLOW_METER.md: Updated wiring instructionsREADME.md: Updated hardware configuration section
- Issue: WiFi and MQTT maintenance functions were called twice in
main.cpploop - Solution: Removed duplicate calls (lines 371-377)
- Impact: Cleaner code, slightly better performance
- Files Changed:
src/main.cpp: Removed duplicatewifi_manager_loop()andmqtt_client_loop()calls
- Feature: Added ESP32 watchdog timer for system recovery
- Configuration:
ENABLE_WATCHDOG: Enable/disable watchdog (default: 1)WATCHDOG_TIMEOUT_SEC: Timeout in seconds (default: 60)
- Behavior: System resets if watchdog is not fed within timeout period
- Files Changed:
include/config.h: Added watchdog configurationsrc/main.cpp: Added watchdog initialization and feeding
- Feature: Improved MQTT JSON payload validation with bounds checking
- Validations Added:
unique_id: Length validation (1-128 characters)cost_per_ml: Range validation (0 < cost <= 1000)max_ml: Range validation (0 < max <= 100000)currency: Valid values (GBP, USD, or empty)
- Error Tracking: Added consecutive error counter with automatic reset
- Recovery: System resets after
MAX_CONSECUTIVE_ERRORS(10) errors - Files Changed:
include/config.h: Added error recovery configurationsrc/main.cpp: Enhanced JSON validation and error tracking
- Test Files Created:
test/test_flow_meter.cpp: Tests for flow rate and volume calculationstest/test_mqtt_json.cpp: Tests for MQTT JSON parsing and validation
- Coverage:
- Flow rate calculations (0, 1, 10, 30 L/min)
- Volume calculations from pulse counts
- Edge cases and boundary conditions
- Valid and invalid JSON payloads
- Field validation logic
- Framework: Unity test framework (PlatformIO default)
- Feature: Added
.clang-formatconfiguration file - Style: Based on Google C++ Style Guide with ESP32/Arduino adaptations
- Settings:
- 4-space indentation
- 100 character line limit
- Attached braces style
- C++11 standard
- Usage: Run
clang-format -i <file>to format code
- Updated all references to flow meter pin from GPIO25 to GPIO26
- Removed pin conflict warnings
- Updated wiring diagrams
- Updated troubleshooting sections
- Files Updated:
docs/HARDWARE_SETUP.mddocs/FLOW_METER.mdREADME.md
// Error Recovery Configuration
#define ENABLE_WATCHDOG 1 // Enable ESP32 watchdog timer
#define WATCHDOG_TIMEOUT_SEC 60 // Watchdog timeout in seconds
#define MAX_CONSECUTIVE_ERRORS 10 // Max errors before reset
#define ERROR_RESET_DELAY_MS 5000 // Delay before reset (ms)| Component | Old Pin | New Pin | Reason |
|---|---|---|---|
| Flow Meter | GPIO25 | GPIO26 | Avoid conflict with TOUCH_SCLK |
To run the new unit tests:
# Run all tests
pio test
# Run specific test
pio test -f test_flow_meter
pio test -f test_mqtt_json
# Verbose output
pio test -vIf you have existing hardware with flow meter connected to GPIO25:
- Option 1 (Recommended): Reconnect flow meter yellow wire to GPIO26
- Option 2: Change
FLOW_METER_PINback to 25 ininclude/config.hif touch is not needed
To format existing code with the new .clang-format:
# Format all C++ files
find src include -name "*.cpp" -o -name "*.h" | xargs clang-format -iAll recommendations from the code review have been implemented:
- ✅ Fixed GPIO25 pin conflict
- ✅ Removed duplicate code
- ✅ Added error recovery (watchdog + validation)
- ✅ Added unit tests
- ✅ Added code formatting configuration
- ✅ Updated documentation
The project is now more robust, maintainable, and better tested.