diff --git a/docs/custom-cli.md b/docs/custom-cli.md index 054994e2..4250e927 100644 --- a/docs/custom-cli.md +++ b/docs/custom-cli.md @@ -51,7 +51,7 @@ Notes: - `letsmesh-eu` and `letsmesh-us` remain off by default unless already configured in saved prefs - if `mqtt.iata` is `UNSET`, `eastmesh-au`, `letsmesh-eu`, and `letsmesh-us` will not connect even if they are toggled on - turning off a connected broker publishes a retained MQTT status update with `"status":"offline"` before the client disconnects -- changing `mqtt.iata` away from a configured value also publishes retained offline status to the old status topic before switching topics +- changing `mqtt.iata` away from a configured value also publishes retained offline status to the old status topic, restarts connected broker clients, and reconnects under the new topic path Legacy dotted aliases are also accepted: diff --git a/docs/web-panel.md b/docs/web-panel.md index 25e45bcc..33185a5b 100644 --- a/docs/web-panel.md +++ b/docs/web-panel.md @@ -222,7 +222,7 @@ Notes: - the current MQTT server states are loaded when the page opens - you can toggle each MQTT server on or off from this panel - turning off a connected MQTT server publishes retained offline status before the client disconnects -- changing `mqtt.iata` away from a configured value publishes retained offline status to the old status topic before the new topic is used +- changing `mqtt.iata` away from a configured value publishes retained offline status to the old status topic, restarts connected broker clients, and reconnects under the new topic path - if all three servers are enabled at once, the panel shows a warning recommending two at most ## `/stats` Overview diff --git a/release-notes.yml b/release-notes.yml index 8c78a239..e053bf0f 100644 --- a/release-notes.yml +++ b/release-notes.yml @@ -570,7 +570,7 @@ releases: text: "Published explicit retained offline status before a connected broker is toggled off, matching operator expectations without relying on last-will behavior that only fires on unclean disconnects." - type: fixed area: mqtt - text: "Published retained offline status to the old status topic before `mqtt.iata` changes, preventing stale online status from remaining under the previous IATA path." + text: "Published retained offline status to the old status topic before `mqtt.iata` changes, then restarted connected broker clients so they reconnect and publish online status under the new IATA path." - type: docs area: mqtt text: "Updated the CLI and web-panel docs to describe retained offline status publishing for broker toggles and IATA changes." diff --git a/src/helpers/mqtt/MQTTUplink.cpp b/src/helpers/mqtt/MQTTUplink.cpp index fee542b5..59e3ea4c 100644 --- a/src/helpers/mqtt/MQTTUplink.cpp +++ b/src/helpers/mqtt/MQTTUplink.cpp @@ -1164,17 +1164,30 @@ bool MQTTUplink::setIata(const char* iata) { for (size_t i = 0; cleaned[i] != 0; ++i) { cleaned[i] = toupper(static_cast(cleaned[i])); } - if (strcmp(cleaned, _prefs.iata) != 0 && !isUnsetIataValue(_prefs.iata)) { + bool changed = strcmp(cleaned, _prefs.iata) != 0; + if (changed && !isUnsetIataValue(_prefs.iata)) { publishStatus(false); } if (strcmp(cleaned, MQTT_UNSET_IATA) == 0) { StrHelper::strncpy(_prefs.iata, MQTT_UNSET_IATA, sizeof(_prefs.iata)); refreshIdentityStrings(); - return savePrefs(); + bool saved = savePrefs(); + if (changed) { + for (BrokerState& broker : _brokers) { + destroyBroker(broker); + } + } + return saved; } StrHelper::strncpy(_prefs.iata, cleaned, sizeof(_prefs.iata)); refreshIdentityStrings(); - return savePrefs(); + bool saved = savePrefs(); + if (changed) { + for (BrokerState& broker : _brokers) { + destroyBroker(broker); + } + } + return saved; } bool MQTTUplink::setOwnerPublicKey(const char* owner_public_key) {