From e00b29b4b84d817ed99a9eddfc7896dcccfa3da1 Mon Sep 17 00:00:00 2001 From: agessaman Date: Mon, 27 Jul 2026 18:34:04 -0700 Subject: [PATCH] feat(mqtt): add per-slot packet filters for MQTT slots Introduce per-slot packet filters to allow users to specify which packet types are uploaded for each MQTT slot. This feature enhances the flexibility of the MQTT bridge by enabling users to configure allowlists for packet types, improving the efficiency of data transmissions. The implementation includes updates to the WebConfig interface, internal handling of packet filters, and necessary modifications to the MQTT preferences structure. --- MQTT_IMPLEMENTATION.md | 34 +++++ MQTT_INTERNALS.md | 9 +- scripts/webconfig_mock_server.py | 31 +++- src/helpers/CommonCLI_Observer.cpp | 23 +++ src/helpers/MQTTDefaults.h | 4 + src/helpers/MQTTPacketFilter.h | 126 +++++++++++++++ src/helpers/MQTTPrefsCodec.h | 6 + src/helpers/MQTTPrefsStorage.h | 15 +- src/helpers/WebConfigKeys.h | 1 + src/helpers/bridges/MQTTBridge.cpp | 72 +++++++-- src/helpers/bridges/MQTTBridge.h | 6 +- src/helpers/esp32/WebConfigServer.cpp | 10 ++ test/README.md | 1 + .../test_mqtt_packet_filter.cpp | 143 ++++++++++++++++++ .../test_mqtt_prefs_codec.cpp | 44 ++++++ .../test_webconfig_keys.cpp | 2 + webui/index.html | 5 +- 17 files changed, 510 insertions(+), 22 deletions(-) create mode 100644 src/helpers/MQTTPacketFilter.h create mode 100644 test/test_mqtt_packet_filter/test_mqtt_packet_filter.cpp diff --git a/MQTT_IMPLEMENTATION.md b/MQTT_IMPLEMENTATION.md index cb94c628..33dd877c 100644 --- a/MQTT_IMPLEMENTATION.md +++ b/MQTT_IMPLEMENTATION.md @@ -248,6 +248,7 @@ The MQTT bridge comes with the following defaults for fresh installs (unless ove - **Slot 1**: `analyzer-us` - **Slot 2**: `analyzer-eu` - **Slots 3-6**: `none` (disabled) +- **Per-slot packet filters**: `all` (every payload type is uploaded) - **WiFi SSID**: (blank — must be configured) - **WiFi Password**: (blank — optional for open networks) - **WiFi Power Save**: `none` (no power save) @@ -272,6 +273,7 @@ Each slot (1-6) supports the following commands: - `get mqttN.token` - Get per-slot token (e.g., MeshRank account token) - `get mqttN.topic` - Get custom topic template for slot N - `get mqttN.audience` - Get JWT audience for slot N (custom slots only) +- `get mqttN.filter` - Get the slot's packet-type allowlist (`all`, `none`, or numeric CSV) #### Set Commands - `set mqttN.preset ` - Set slot N to a built-in preset. Use any `name` from the [preset table](#slot-based-preset-system) (run `get mqtt.presets` on-device for the full list). Most presets need no further configuration; the exceptions are: @@ -287,9 +289,41 @@ Each slot (1-6) supports the following commands: - `set mqttN.topic