From e624a4177db5b3d6f1a276ff83ad9cb37b97ce7e Mon Sep 17 00:00:00 2001 From: cjkas Date: Thu, 15 Oct 2026 19:41:49 +0200 Subject: [PATCH] refactor: move the transports into entryPoints and outputs The HTTP servers and MQTT command handling go to src/entryPoints/, the socket emitter and the MQTT and socket output of shades, groups and rooms to src/outputs/. GLOSSARY.md names what they become once split: WebUiRoutes, ApiRoutes and MqttCommands in, MqttPublisher and SocketEmitter out. Only files and include paths change. esp32devdbg flash goes from 1,546,405 to 1,546,257 bytes. Co-Authored-By: Claude Opus 5.5 --- GLOSSARY.md | 26 ++++++++++++++++++++++++++ docs/KNOWN_ISSUES.md | 6 +++--- docs/SOMFY_SPLIT_PLAN.md | 1 + src/ESPNetwork.cpp | 6 +++--- src/GitOTA.cpp | 4 ++-- src/SomfyController.ino | 6 +++--- src/Transceiver.cpp | 2 +- src/WebCommand.h | 2 +- src/{ => entryPoints}/MQTT.cpp | 0 src/{ => entryPoints}/MQTT.h | 0 src/{ => entryPoints}/Web.cpp | 0 src/{ => entryPoints}/Web.h | 0 src/{ => outputs}/Sockets.cpp | 0 src/{ => outputs}/Sockets.h | 0 src/{ => outputs}/SomfyEvents.cpp | 2 +- src/{ => outputs}/SomfyMqtt.cpp | 2 +- 16 files changed, 42 insertions(+), 15 deletions(-) rename src/{ => entryPoints}/MQTT.cpp (100%) rename src/{ => entryPoints}/MQTT.h (100%) rename src/{ => entryPoints}/Web.cpp (100%) rename src/{ => entryPoints}/Web.h (100%) rename src/{ => outputs}/Sockets.cpp (100%) rename src/{ => outputs}/Sockets.h (100%) rename src/{ => outputs}/SomfyEvents.cpp (99%) rename src/{ => outputs}/SomfyMqtt.cpp (99%) diff --git a/GLOSSARY.md b/GLOSSARY.md index bd1a908..05c6a13 100644 --- a/GLOSSARY.md +++ b/GLOSSARY.md @@ -51,3 +51,29 @@ The per-shade switch that lets the sun move a shade. While it is on, lasting sun **Extend / retract** Where the weather sends a shade: extend to its favorite, or fully when it has none; retract fully. A tilt-only shade extends and retracts its tilt, every other shade its lift. + +## Entry points and outputs + +**Entry point** +Where a request from outside reaches the firmware: an HTTP route, an MQTT command topic or a frame received from a remote. +_Avoid_: controller (it already names the owner of the shade list and the `/controller` read) + +**WebUiRoutes** +The HTTP routes on port 80 that the config web UI calls, plus the UI's own files. +_Avoid_: WebUiController, Web + +**ApiRoutes** +The HTTP routes on port 8081 that integrations such as Home Assistant call. +_Avoid_: WebApiController + +**MqttCommands** +The MQTT topics ending in `/set` that command a shade or group. +_Avoid_: MQTTController + +**MqttPublisher** +What sends the state of rooms, shades and groups, and the Home Assistant discovery config, to the MQTT broker. +_Avoid_: MQTTController + +**SocketEmitter** +What pushes state events to WebSocket clients on port 8080. A client can only join or leave a room; it sends no commands. +_Avoid_: WebSocketController diff --git a/docs/KNOWN_ISSUES.md b/docs/KNOWN_ISSUES.md index 5d5bd1e..43fccdf 100644 --- a/docs/KNOWN_ISSUES.md +++ b/docs/KNOWN_ISSUES.md @@ -3,7 +3,7 @@ ## Concurrent mutation during chunked `/controller` response **Status:** open -**Introduced:** 2026-04-19, alongside the chunked-response conversion of `/controller` (see [`ControllerChunker` in src/Web.cpp](../src/Web.cpp) and the original crash report about `cbuf::resize` aborting `async_tcp`). +**Introduced:** 2026-04-19, alongside the chunked-response conversion of `/controller` (see [`ControllerChunker` in src/entryPoints/Web.cpp](../src/entryPoints/Web.cpp) and the original crash report about `cbuf::resize` aborting `async_tcp`). ### Summary @@ -42,7 +42,7 @@ The new `ControllerChunker` reads state as the response drains. On a slow link o ## Oversized `/controller` items are left out **Status:** open -**Location:** `ControllerChunker::overflowed` in [src/Web.cpp](../src/Web.cpp). +**Location:** `ControllerChunker::overflowed` in [src/entryPoints/Web.cpp](../src/entryPoints/Web.cpp). ### Summary @@ -67,7 +67,7 @@ A shade with every linked remote populated is about 1.5 KB today, so nothing ove ## Large websocket events are dropped **Status:** open -**Location:** [`JsonSockEvent` in src/WResp.cpp](../src/WResp.cpp), buffer `g_response[MAX_SOCK_RESPONSE]` (2048 bytes) in [src/Sockets.cpp](../src/Sockets.cpp). +**Location:** [`JsonSockEvent` in src/WResp.cpp](../src/WResp.cpp), buffer `g_response[MAX_SOCK_RESPONSE]` (2048 bytes) in [src/outputs/Sockets.cpp](../src/outputs/Sockets.cpp). ### Summary diff --git a/docs/SOMFY_SPLIT_PLAN.md b/docs/SOMFY_SPLIT_PLAN.md index e90ab26..c0c04fc 100644 --- a/docs/SOMFY_SPLIT_PLAN.md +++ b/docs/SOMFY_SPLIT_PLAN.md @@ -2,6 +2,7 @@ **Status:** done. Phases 0 and 1 in `bbfb23e`..`505108c`, phase 2 in `0eb0e63`..`a176017` (2026-10-13). **Written:** 2026-10-13, against commit `4544eb6` on `fix/live-bugs`. Line numbers in the analysis below refer to that commit. The code now lives in the files listed under [Phase 1](#phase-1-split-the-file-by-concern). +Since then `SomfyMqtt.cpp` and `SomfyEvents.cpp` have moved to `src/outputs/`. ## Why diff --git a/src/ESPNetwork.cpp b/src/ESPNetwork.cpp index afc39ed..9bad48e 100644 --- a/src/ESPNetwork.cpp +++ b/src/ESPNetwork.cpp @@ -13,11 +13,11 @@ static inline void safe_wdt_reset() { } #include "ConfigSettings.h" #include "ESPNetwork.h" -#include "Web.h" -#include "Sockets.h" +#include "entryPoints/Web.h" +#include "outputs/Sockets.h" #include "Utils.h" #include "SSDP.h" -#include "MQTT.h" +#include "entryPoints/MQTT.h" static const char *TAG = "Network"; diff --git a/src/GitOTA.cpp b/src/GitOTA.cpp index 19d8289..e0913e0 100644 --- a/src/GitOTA.cpp +++ b/src/GitOTA.cpp @@ -8,9 +8,9 @@ #include "ConfigSettings.h" #include "GitOTA.h" #include "Utils.h" -#include "Sockets.h" +#include "outputs/Sockets.h" #include "Somfy.h" -#include "Web.h" +#include "entryPoints/Web.h" #include "WResp.h" #include "ESPNetwork.h" diff --git a/src/SomfyController.ino b/src/SomfyController.ino index 91e351f..b0e2941 100644 --- a/src/SomfyController.ino +++ b/src/SomfyController.ino @@ -4,11 +4,11 @@ #include #include "ConfigSettings.h" #include "ESPNetwork.h" -#include "Web.h" -#include "Sockets.h" +#include "entryPoints/Web.h" +#include "outputs/Sockets.h" #include "Utils.h" #include "Somfy.h" -#include "MQTT.h" +#include "entryPoints/MQTT.h" #include "GitOTA.h" #include "esp_core_dump.h" #include "esp_system.h" diff --git a/src/Transceiver.cpp b/src/Transceiver.cpp index 24b13bd..9179a91 100644 --- a/src/Transceiver.cpp +++ b/src/Transceiver.cpp @@ -10,7 +10,7 @@ #include "Utils.h" #include "ConfigSettings.h" #include "Somfy.h" -#include "Sockets.h" +#include "outputs/Sockets.h" static const char *TAG = "Somfy"; diff --git a/src/WebCommand.h b/src/WebCommand.h index 580c0aa..43187aa 100644 --- a/src/WebCommand.h +++ b/src/WebCommand.h @@ -3,7 +3,7 @@ #include #include "SomfyFrame.h" -// Commands the web servers hand to the main loop (src/Web.cpp). Kept free of +// Commands the web servers hand to the main loop (src/entryPoints/Web.cpp). Kept free of // the web server and FreeRTOS so it can be unit tested on the PC // (pio test -e native). diff --git a/src/MQTT.cpp b/src/entryPoints/MQTT.cpp similarity index 100% rename from src/MQTT.cpp rename to src/entryPoints/MQTT.cpp diff --git a/src/MQTT.h b/src/entryPoints/MQTT.h similarity index 100% rename from src/MQTT.h rename to src/entryPoints/MQTT.h diff --git a/src/Web.cpp b/src/entryPoints/Web.cpp similarity index 100% rename from src/Web.cpp rename to src/entryPoints/Web.cpp diff --git a/src/Web.h b/src/entryPoints/Web.h similarity index 100% rename from src/Web.h rename to src/entryPoints/Web.h diff --git a/src/Sockets.cpp b/src/outputs/Sockets.cpp similarity index 100% rename from src/Sockets.cpp rename to src/outputs/Sockets.cpp diff --git a/src/Sockets.h b/src/outputs/Sockets.h similarity index 100% rename from src/Sockets.h rename to src/outputs/Sockets.h diff --git a/src/SomfyEvents.cpp b/src/outputs/SomfyEvents.cpp similarity index 99% rename from src/SomfyEvents.cpp rename to src/outputs/SomfyEvents.cpp index 75b6cdd..eeab2f0 100644 --- a/src/SomfyEvents.cpp +++ b/src/outputs/SomfyEvents.cpp @@ -1,7 +1,7 @@ #include #include "Somfy.h" #include "Sockets.h" -#include "MQTT.h" +#include "entryPoints/MQTT.h" extern SomfyShadeController somfy; extern SocketEmitter sockEmit; diff --git a/src/SomfyMqtt.cpp b/src/outputs/SomfyMqtt.cpp similarity index 99% rename from src/SomfyMqtt.cpp rename to src/outputs/SomfyMqtt.cpp index 04a3200..4b07edf 100644 --- a/src/SomfyMqtt.cpp +++ b/src/outputs/SomfyMqtt.cpp @@ -2,7 +2,7 @@ #include "ConfigSettings.h" #include "Somfy.h" #include "Sockets.h" -#include "MQTT.h" +#include "entryPoints/MQTT.h" extern SomfyShadeController somfy; extern SocketEmitter sockEmit;