Skip to content

Commit

Permalink
Fixes for MQTT client
Browse files Browse the repository at this point in the history
- Fix setting connect flags related to LWT
- Display debug message when changing subscription QOS
- Replace max QOS argument
  • Loading branch information
rechrtb committed Sep 16, 2023
1 parent 2c1d9be commit e10c385
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/Networking/MQTT/MqttClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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
{
Expand Down

0 comments on commit e10c385

Please sign in to comment.