From aa780ee943e3226705fac73574c71980bd4a1113 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 18 Nov 2022 13:19:12 +0100 Subject: [PATCH] MQTT client: Fix a crash when failing to connect to the internal broker --- mqttclient/integrationpluginmqttclient.cpp | 5 +++ ...58205-07c8-4482-85ad-b435387803a5-en_US.ts | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/mqttclient/integrationpluginmqttclient.cpp b/mqttclient/integrationpluginmqttclient.cpp index 37fe5b71..0fe40891 100644 --- a/mqttclient/integrationpluginmqttclient.cpp +++ b/mqttclient/integrationpluginmqttclient.cpp @@ -50,6 +50,11 @@ void IntegrationPluginMqttClient::setupThing(ThingSetupInfo *info) } if (thing->thingClassId() == internalMqttClientThingClassId) { client = hardwareManager()->mqttProvider()->createInternalClient(thing->id().toString()); + if (!client) { + info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Unable to to connect to internal MQTT broker. Verify the MQTT broker is set up and running.")); + return; + } + } else if (thing->thingClassId() == mqttClientThingClassId){ client = new MqttClient(thing->paramValue(mqttClientThingClientIdParamTypeId).toString(), this); client->setUsername(thing->paramValue(mqttClientThingUsernameParamTypeId).toString()); diff --git a/mqttclient/translations/27c58205-07c8-4482-85ad-b435387803a5-en_US.ts b/mqttclient/translations/27c58205-07c8-4482-85ad-b435387803a5-en_US.ts index 60882916..42a74052 100644 --- a/mqttclient/translations/27c58205-07c8-4482-85ad-b435387803a5-en_US.ts +++ b/mqttclient/translations/27c58205-07c8-4482-85ad-b435387803a5-en_US.ts @@ -1,6 +1,17 @@ + + IntegrationPluginMqttClient + + Unable to to connect to internal MQTT broker. Verify the MQTT broker is set up and running. + + + + 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. + + + mqttclient @@ -100,5 +111,35 @@ The name of the ParamType (ThingClass: internalMqttClient, EventType: triggered, The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) + + Client Id + The name of the ParamType (ThingClass: mqttClient, Type: thing, ID: {621f9054-2b64-4de9-93d2-65bba96a14a3}) + + + + Retain will + The name of the ParamType (ThingClass: mqttClient, Type: thing, ID: {c7fba1f0-a7b0-4162-8b50-fb85697fe678}) + + + + Use SSL + The name of the ParamType (ThingClass: mqttClient, Type: thing, ID: {714074bd-1ab1-4ee6-b6db-7594b3dbf56f}) + + + + Will QoS + The name of the ParamType (ThingClass: mqttClient, Type: thing, ID: {470b600d-e1c1-4ae7-83d4-0179600e4187}) + + + + Will message + The name of the ParamType (ThingClass: mqttClient, Type: thing, ID: {acb19fba-d140-4ff1-b4ec-3b933c04417e}) + + + + Will topic + The name of the ParamType (ThingClass: mqttClient, Type: thing, ID: {04aa1f25-4ee9-4bce-9844-a9860642c938}) + +