MQTT client: Add more parameters to thing class (for SSL and will)

master
Michael Zanetti 2021-12-15 13:31:58 +01:00
parent 74290ca1a3
commit 7c6fc0311f
3 changed files with 54 additions and 1 deletions

View File

@ -51,10 +51,24 @@ void IntegrationPluginMqttClient::setupThing(ThingSetupInfo *info)
client = new MqttClient("nymea-" + thing->id().toString().remove(QRegExp("[{}]")).left(8), this);
client->setUsername(thing->paramValue(mqttClientThingUsernameParamTypeId).toString());
client->setPassword(thing->paramValue(mqttClientThingPasswordParamTypeId).toString());
client->connectToHost(thing->paramValue(mqttClientThingServerAddressParamTypeId).toString(), thing->paramValue(mqttClientThingServerPortParamTypeId).toInt());
QString willTopic = thing->paramValue(mqttClientThingWillTopicParamTypeId).toString();
if (!willTopic.isEmpty()) {
client->setWillTopic(willTopic);
client->setWillMessage(thing->paramValue(mqttClientThingWillMessageParamTypeId).toByteArray());
client->setWillQoS(static_cast<Mqtt::QoS>(thing->paramValue(mqttClientThingWillQoSParamTypeId).toInt()));
client->setWillRetain(thing->paramValue(mqttClientThingWillRetainParamTypeId).toBool());
}
client->connectToHost(thing->paramValue(mqttClientThingServerAddressParamTypeId).toString(),
thing->paramValue(mqttClientThingServerPortParamTypeId).toInt(),
true,
thing->paramValue(mqttClientThingUseSslParamTypeId).toBool());
}
m_clients.insert(thing, client);
connect(client, &MqttClient::error, info, [info](QAbstractSocket::SocketError socketError){
qCWarning(dcMqttclient()) << "An error happened during setup:" << socketError;
info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("An error happened connecting to the MQTT broker. Please make sure the login credentials are correct and your user has apprpriate permissions to subscribe to the given topic filter."));
});
connect(client, &MqttClient::connected, this, [this, thing](){
subscribe(thing);
});

View File

@ -37,6 +37,8 @@
#include <QDebug>
#include <QUdpSocket>
#include "extern-plugininfo.h"
class MqttClient;
class IntegrationPluginMqttClient: public IntegrationPlugin

View File

@ -127,6 +127,43 @@
"displayName": "Subscription topic filter",
"type": "QString",
"defaultValue": "#"
},
{
"id": "714074bd-1ab1-4ee6-b6db-7594b3dbf56f",
"name": "useSsl",
"displayName": "Use SSL",
"type": "bool",
"defaultValue": false
},
{
"id": "04aa1f25-4ee9-4bce-9844-a9860642c938",
"name": "willTopic",
"displayName": "Will topic",
"type": "QString",
"defaultValue": ""
},
{
"id": "acb19fba-d140-4ff1-b4ec-3b933c04417e",
"name": "willMessage",
"displayName": "Will message",
"type": "QString",
"defaultValue": ""
},
{
"id": "c7fba1f0-a7b0-4162-8b50-fb85697fe678",
"name": "willRetain",
"displayName": "Retain will",
"type": "bool",
"defaultValue": false
},
{
"id": "470b600d-e1c1-4ae7-83d4-0179600e4187",
"name": "willQoS",
"displayName": "Will QoS",
"type": "uint",
"minValue": 0,
"maxValue": 2,
"defaultValue": 0
}
],
"eventTypes": [