Merge PR #520: MQTT client: Add more parameters to thing class (for SSL and will)
commit
9ecc91f179
|
|
@ -45,16 +45,33 @@ void IntegrationPluginMqttClient::setupThing(ThingSetupInfo *info)
|
||||||
Thing *thing = info->thing();
|
Thing *thing = info->thing();
|
||||||
|
|
||||||
MqttClient *client = nullptr;
|
MqttClient *client = nullptr;
|
||||||
|
if (m_clients.contains(thing)) {
|
||||||
|
delete m_clients.take(thing);
|
||||||
|
}
|
||||||
if (thing->thingClassId() == internalMqttClientThingClassId) {
|
if (thing->thingClassId() == internalMqttClientThingClassId) {
|
||||||
client = hardwareManager()->mqttProvider()->createInternalClient(thing->id().toString());
|
client = hardwareManager()->mqttProvider()->createInternalClient(thing->id().toString());
|
||||||
} else if (thing->thingClassId() == mqttClientThingClassId){
|
} else if (thing->thingClassId() == mqttClientThingClassId){
|
||||||
client = new MqttClient("nymea-" + thing->id().toString().remove(QRegExp("[{}]")).left(8), this);
|
client = new MqttClient(thing->paramValue(mqttClientThingClientIdParamTypeId).toString(), this);
|
||||||
client->setUsername(thing->paramValue(mqttClientThingUsernameParamTypeId).toString());
|
client->setUsername(thing->paramValue(mqttClientThingUsernameParamTypeId).toString());
|
||||||
client->setPassword(thing->paramValue(mqttClientThingPasswordParamTypeId).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);
|
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](){
|
connect(client, &MqttClient::connected, this, [this, thing](){
|
||||||
subscribe(thing);
|
subscribe(thing);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QUdpSocket>
|
#include <QUdpSocket>
|
||||||
|
|
||||||
|
#include "extern-plugininfo.h"
|
||||||
|
|
||||||
class MqttClient;
|
class MqttClient;
|
||||||
|
|
||||||
class IntegrationPluginMqttClient: public IntegrationPlugin
|
class IntegrationPluginMqttClient: public IntegrationPlugin
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,13 @@
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"defaultValue": ""
|
"defaultValue": ""
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "621f9054-2b64-4de9-93d2-65bba96a14a3",
|
||||||
|
"name": "clientId",
|
||||||
|
"displayName": "Client Id",
|
||||||
|
"type": "QString",
|
||||||
|
"defaultValue": "nymea"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "d8211599-52f7-46f6-a741-a7204b987309",
|
"id": "d8211599-52f7-46f6-a741-a7204b987309",
|
||||||
"name": "password",
|
"name": "password",
|
||||||
|
|
@ -127,6 +134,43 @@
|
||||||
"displayName": "Subscription topic filter",
|
"displayName": "Subscription topic filter",
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"defaultValue": "#"
|
"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": [
|
"eventTypes": [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue