This plan details the architecture and implementation steps to build a fresh, state-of-the-art Pool Controller featuring a premium, password-protected Web Setup Portal (Captive Portal), pure Home Assistant MQTT Discovery, and standard security features (MQTT TLS, signed OTA, and flash encryption).
[!IMPORTANT] > Key Decisions & Requirements (Updated):
- Fresh Installation (No Migration): Backward compatibility with Homie
/homie/config.jsonmigration is not required. We are doing a clean installation usingLittleFSand/config.json.- Captive Web Portal: If no configuration exists or WiFi connection fails (20-second timeout), the device automatically starts a WiFi Access Point (
Pool-Controller-Setup) and a DNS captive portal.- Password-Protected Web Interface: Once connected to the home network, the web interface remains accessible at the local IP but requires a password (configurable by the user during setup, e.g., default
admin) to read/write settings.- Premium Design: The Web UI will be designed with high-end glassmorphism, responsive controls, live charts, and smooth animations matching a luxury smart-home application.
- Standard Security & ArduinoJson v7: Includes full MQTT TLS, signed OTA firmware build profiles, and the modern ArduinoJson 7.x API.
Instead of the unmaintained Homie framework, the system will use a highly robust, cooperative, and modular architecture:
graph TD
Main[main.cpp] --> PC[PoolControllerContext]
PC --> CM[ConfigManager]
PC --> NM[NetworkManager]
PC --> WP[WebPortal]
PC --> OM[OperationModeNode]
PC --> SM[SystemMonitor]
PC --> DM[DegradationManager]
NM --> MQTT[PubSubClient / TLS]
NM --> WIFI[WiFi STA]
WP --> WS[WebServer / Captive Portal]
CM --> LFS[LittleFS / config.json]
- Storage:
/config.jsononLittleFSstoring WiFi, MQTT, NTP, setpoint configurations, and the web admin password hash. - JSON Library: Upgraded to ArduinoJson v7 for memory efficiency and safe allocations.
- Libraries: Standard Espressif
WebServer.handDNSServer.h. Extremely stable, no memory leaks. - AP Mode: If WiFi fails or
/config.jsonis missing, the controller spawns aPool-Controller-SetupAP and redirects all DNS queries to192.168.4.1. - Aesthetics: Premium responsive UI with a dark glassmorphism design:
- Teal/Cyan accent colors (refreshing pool water look).
- Amber/Orange accents for solar pump activation.
- Interactive forms for WiFi (with network scan), MQTT, and setpoints.
- Password Protection: Accessing the API/Web UI on STA mode requires authentication. Session tokens or basic authentication will be enforced.
- Remove
git+https://github.com/homieiot/homie-esp8266.git#developandmarvinroger/AsyncMqttClient. - Add
knolleary/PubSubClient(or approved alternative) andbblanchon/ArduinoJson @ 7.3.0. - Upgrade platform to
espressif32 @ 6.9.0. - Configure partitions to support
LittleFSinstead of SPIFFS.
- Mount
LittleFSand manage serialization/deserialization of/config.json. - Store hashed admin passwords for the Web UI.
- Manage STA connection, reconnection cycles, and status updates.
- Handle WPS provisioning.
- Initialize standard
PubSubClientwithWiFiClientSecurefor TLS.
- Serve the premium Web UI assets (HTML/CSS/JS).
- Implement the Captive Portal DNS redirection.
- Expose API endpoints for:
/api/scan— scan WiFi networks./api/config— read/write system configuration (password-protected on STA mode)./api/status— read live sensor values and pump states.
- Support password validation using simple SHA-256 or secure comparison.
- Replace all Homie framework setups, events, and settings with
ConfigManager,NetworkManager, andWebPortal. - Implement non-blocking state checks in
loop().
- Publish Home Assistant Discovery and state updates.
- Consolidate all entities into a single "Pool Controller" device using the MAC address as the identifier (F5 Fix).
- Implement LWT and availability topic (F6 Fix).
- Expose diagnostics (F8 Fix).
- Move duplicate
checkPoolPumpTimer()logic fromRuleAutoandRuleTimerinto this base class (F21 Fix). - Mark getters as
const(F23 Fix).
- Remove duplicate code.
- Replace Homie loggers with modern injected or static system logger.
- Prevent serial block timeout (F29 Fix).
- Password-Protected Web UI:
- The setup page will require setting a strong password.
- When accessed in station mode, a premium login screen will be displayed.
- Uses HTTP session cookies or token validation.
- MQTT TLS (F10):
- Configure
WiFiClientSecurewith the broker's TLS configurations. - Support both full Root CA certificate validation and insecure TLS (via config).
- Configure
- Flash Encryption & Secure Boot Support (F1, F11, F14):
- Provide platformio build profiles with ESP32 partition tables supporting signed OTA updates and app rollbacks.
- Prevent plaintext credential writing by using ESP32 Flash Encryption.
- Document concrete commands for physical key burning (
espsecure.py,espefuse.py) indocs/security-setup.md.
- Signed OTA (F1, F2, F3):
- Integrate ESP32 anti-rollback APIs (
esp_ota_mark_app_valid_cancel_rollback()). - Deliver OTA firmware chunks securely over HTTPS via the Home Assistant MQTT Update Entity.
- Integrate ESP32 anti-rollback APIs (
- Compilation Validation: Run
pio runto verify that all new LittleFS, WebServer, ArduinoJson 7.x, and PubSubClient integrations compile flawlessly. - Unit Testing: Run
pio teston core rule engines to ensure the extracted base classcheckPoolPumpTimer()functions correctly under normal and midnight-crossing schedules.
- Captive Portal Verification: Connect to
Pool-Controller-SetupAP, navigate tohttp://192.168.4.1, scan networks, enter credentials, and configure settings. - API Protection Verification: Confirm that accessing
/api/configwithout a valid password session returns a401 Unauthorizederror when in STA mode. - HA Entity Consolidation: Connect the controller to an MQTT broker, observe HA Discovery payloads, and confirm that all entities belong to exactly one unified device in Home Assistant.