mirror of
https://github.com/mikecarper/MeshCore.git
synced 2026-09-26 17:38:16 +00:00
fix(mqtt): honour mqtt.status off for the on-connect status message
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.
This commit is contained in:
@@ -531,7 +531,7 @@ These settings apply across all MQTT slots:
|
||||
#### Set Commands
|
||||
- `set mqtt.origin <name>` - Set device origin name
|
||||
- `set mqtt.iata <code>` - 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
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user