From a728d7542cb8ebef68f0cc69bf61ce815f64751f Mon Sep 17 00:00:00 2001 From: agessaman Date: Wed, 9 Sep 2026 14:45:06 -0700 Subject: [PATCH] fix(mqtt): honour `mqtt.status off` for the on-connect status message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only the periodic status path consulted the setting. The connect callback armed a status publish unconditionally and publishStatusToSlot() never checked it, so every boot and every reconnect published a status message — including the metadata an operator turned the setting off to suppress. The documented contract is "Enable/disable status messages". Read the toggle live from prefs at publish time, matching the periodic path, and also skip a slot the operator has disabled: teardown only stops a client that reports connected, so a slot switched off mid-connect can still complete its handshake and arm this publish. --- MQTT_IMPLEMENTATION.md | 2 +- src/helpers/bridges/MQTTBridge.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/MQTT_IMPLEMENTATION.md b/MQTT_IMPLEMENTATION.md index baf39ed6..9d4d16bc 100644 --- a/MQTT_IMPLEMENTATION.md +++ b/MQTT_IMPLEMENTATION.md @@ -531,7 +531,7 @@ These settings apply across all MQTT slots: #### Set Commands - `set mqtt.origin ` - Set device origin name - `set mqtt.iata ` - Set IATA code (auto-uppercased) -- `set mqtt.status on|off` - Enable/disable status messages +- `set mqtt.status on|off` - Enable/disable status messages (periodic *and* the one sent on each broker connect) - `set mqtt.packets on|off` - Enable/disable packet messages - `set mqtt.raw on|off` - Enable/disable raw messages - `set mqtt.rx on|off` - Enable/disable RX (received) packet uplinking diff --git a/src/helpers/bridges/MQTTBridge.cpp b/src/helpers/bridges/MQTTBridge.cpp index 056af62a..7fa5d69e 100644 --- a/src/helpers/bridges/MQTTBridge.cpp +++ b/src/helpers/bridges/MQTTBridge.cpp @@ -2604,6 +2604,16 @@ void MQTTBridge::publishStatusToSlot(int index) { if (index < 0 || index >= RUNTIME_MQTT_SLOTS) return; MQTTSlot& slot = _slots[index]; if (!slot.client || !slot.connected) return; + // `set mqtt.status off` disables status messages, on-connect ones included + // (MQTT_IMPLEMENTATION.md: "Enable/disable status messages"). Read live from + // prefs like the periodic path, and checked here rather than at the pending + // flag so the setting that counts is the one in force when we publish. + if (!_obs->mqtt_status_enabled) return; + // A disabled slot can still hold a connection that was established before it + // was switched off (teardown only stops a client reporting connected), and + // its callback arms this publish. Do not speak for a slot the operator + // turned off. + if (!slot.enabled) return; refreshOriginFromPrefs();