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();