From e10c385fef1f2728d288424c2b54a5bd7e6ee082 Mon Sep 17 00:00:00 2001 From: rechrtb Date: Fri, 15 Sep 2023 20:33:05 +0900 Subject: [PATCH] Fixes for MQTT client - Fix setting connect flags related to LWT - Display debug message when changing subscription QOS - Replace max QOS argument --- src/Networking/MQTT/MqttClient.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Networking/MQTT/MqttClient.cpp b/src/Networking/MQTT/MqttClient.cpp index 82ff665951..501f67af31 100644 --- a/src/Networking/MQTT/MqttClient.cpp +++ b/src/Networking/MQTT/MqttClient.cpp @@ -385,27 +385,34 @@ void MqttClient::ConnectionLost() noexcept } } + uint8_t flags = 0; + switch (qos) { case 1: - client->connectFlags |= MQTT_CONNECT_WILL_QOS_1; + flags |= MQTT_CONNECT_WILL_QOS_1; break; case 2: - client->connectFlags |= MQTT_CONNECT_WILL_QOS_2; + flags |= MQTT_CONNECT_WILL_QOS_2; break; case 0: default: - client->connectFlags |= MQTT_CONNECT_WILL_QOS_0; + flags |= MQTT_CONNECT_WILL_QOS_0; break; } if (retain) { - client->connectFlags |= MQTT_CONNECT_WILL_RETAIN; + flags |= MQTT_CONNECT_WILL_RETAIN; } + // Bit 3, 4 for QOS and bit 5 for retain. Make sure in sync with definition + // in MQTTConnectFlags. + uint8_t mask = (0x03 << 3) | 32u; + client->connectFlags = (client->connectFlags & ~mask) | (flags & mask); + if (reprap.Debug(Module::Webserver)) { debugPrintf("Set will message '%s' with topic '%s', QOS=%d, retain = %s\n", @@ -419,7 +426,7 @@ void MqttClient::ConnectionLost() noexcept // Check the max QOS first int qos = 0; - if (gb.Seen('M')) + if (gb.Seen('O')) { qos = gb.GetIValue(); if (qos < 0 || qos > 2) @@ -443,6 +450,11 @@ void MqttClient::ConnectionLost() noexcept { // Just overwrite the existing QOS sub->qos = qos; + + if (reprap.Debug(Module::Webserver)) + { + debugPrintf("Subscription topic '%s' max QOS changed to %d \n", param.c_str(), qos); + } } else {