MQTT Last will and testament support

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
StKa_2187866
Level 2
Level 2
First like received

Hi all,

I recently started my baby steps into the IoT universe and I have faced an issue with the MQTT library in WICED SDK 3.5.2.

I am trying to connect my device to Azure's IoT Hub, which supports MQTT's Last Will and Testament (LWT) feature. However the LWT functionality does not seem to be exposed through mqtt_api.h.

Looking into the wiced_mqtt_connect() function, I can see that some boilerplate code is present, but the feature is switched off. So, I was wondering if there are there any plans to provide proper support for LWT in the MQTT library?

Thanks,

Stavros.

0 Likes
11 Replies
AxLi_1746341
Level 7
Level 7
10 comments on KBA 5 comments on KBA First comment on KBA

Hi,

Is there any documentation for connecting WICED to Azure's IoT Hub using MQTT?

Thanks,

Axel

0 Likes

Haven't seen any. However, the MQTT examples that come with WICED 3.5.2 work fairly easily.

The only thing you need to do is to configure the CA of the SSL certificate in your device so that it accepts the connection from Azure IoT. The cert I am referring to is the  "Baltimore CyberTrust Root" and should be already in your certificate store.

Just export it as .pem format and pass it in as the ca_cert in the security argument of the mqtt_conn_open() function.

Good luck

I'm referencing below doc:

https://github.com/Azure/azure-content/blob/master/articles/iot-hub/iot-hub-mqtt-support.md#using-th...

It needs below settings to make mqtt connection.

* ClientID

* Username

* Password

The description seems different from yours.

Do you have a example settings using mosquitto tool to test Azure IoT?

Thanks.

0 Likes

Hi axel.lin​,

My description is complementary to the document you linked. I just describe a step that is not covered in the WICED SDK for Azure-specific connections through MQTT.

Indeed,  ClientID, Username and Password must be defined as that document describes. But you also need to make sure that you use the secure MQTT (port 8883) because Azure will accept no other.

Here is an example connection profile that I would have imported in MQTT.fx if I was to use the Azure IoT Hub that is described in the document you pointed at:

{

  "connectionProfiles" : [ {

    "recentSubscriptionTopics" : [ ],

    "recentPublishTopics" : [ ],

    "preDefinedMessages" : [ ],

    "brokerAddress" : "contoso.azure-devices.net",

    "brokerPort" : "8883",

    "lastPublishTopic" : null,

    "lastSubscriptionTopic" : null,

    "profileName" : "MyDevice01@Contoso",

    "scriptsPath" : "",

    "connectionOptions" : {

      "clientId" : "paho398791429784759",

      "connectionTimeout" : 30,

      "keepAliveInterval" : 60,

      "mqttVersionUseDefault" : true,

      "mqttVersion" : "3.1.1",

      "cleanSession" : true,

      "userName" : "contoso.azure-devices.net/MyDevice01",

      "password" : "SharedAccessSignature sr={your hub name}.azure-devices.net%2fdevices%2fyDevice01&sig=vSgHBMUG.....Ntg%3d&se=1456481802g%3d&se=1456481802",

      "lwtQos" : 1,

      "lwtRetained" : false,

      "lastWillDestination" : "devices/MyDevice01/messages/events/dead",

      "testament" : "",

      "useProxy" : false,

      "useHttpsProxy" : false,

      "httpsProxyHost" : "",

      "httpsProxyPort" : "",

      "httpProxyHost" : "",

      "httpProxyPort" : "",

      "httpProxyUser" : "",

      "httpProxyPassword" : "",

      "enableSSLTLS" : true,

      "sslTlsProtocol" : "TLSv1.2",

      "certificateFilesPemFormat" : false,

      "selfCreatedCaFile" : "",

      "caFile" : "",

      "clientCertificateFile" : "",

      "clientKeyFile" : "",

      "clientKeyPassword" : "",

      "useSelfCreatedCA" : false,

      "useServerSignedCertificate" : true,

      "useTrustedKeystoreFile" : false,

      "useCertificateFiles" : false,

      "useKeystoreFiles" : false,

      "clientKeystoreFilesPemFormat" : false,

      "trustedKeystoreOnlyFile" : "",

      "trustedKeystoreOnlyPassword" : "",

      "trustedKeystoreFile" : "",

      "trustedKeystoreAlias" : "",

      "trustedKeystorePassword" : "",

      "clientKeystoreFile" : "",

      "clientKeystorePassword" : "",

      "clientKeyPairAlias" : "",

      "clientKeyPairPassword" : ""

    },

    "notificatonsEnabled" : false,

    "showLastestMessagesOnly" : false

  } ]

}

I hope this helps.

Also, I hope that someone has an insight into my original question.

Cheers,

Stavros.

Adding vik86​ as he may know the answer to your original question.

Thanks for the help.

0 Likes
Anonymous
Not applicable

Is LWT supported in  v3.7.0?

0 Likes

suchitra.hullur wrote:

Is LWT supported in  v3.7.0?

No.

0 Likes
Anonymous
Not applicable

Hi Axel.lin, is LWT support added in SDK v4.0.1?

0 Likes

suchitra.hullur wrote:

Hi Axel.lin, is LWT support added in SDK v4.0.1?

No. ( But it's easy to implement supporting LWT by yourself).

0 Likes

Truth is that it LWT is not exposed in WICED SDK's API, but the guts seem to be in place.

With a few modifications you could make LWT work even in 3.5.2. This is what we have done and we have been utilizing LWT against Azure's IoT Hub service.

kafouros wrote:

Hi axel.lin_1746341,

My description is complementary to the document you linked. I just describe a step that is not covered in the WICED SDK for Azure-specific connections through MQTT.

Indeed,  ClientID, Username and Password must be defined as that document describes. But you also need to make sure that you use the secure MQTT (port 8883) because Azure will accept no other.

Here is an example connection profile that I would have imported in MQTT.fx if I was to use the Azure IoT Hub that is described in the document you pointed at:

{

  "connectionProfiles" : [ {

    "recentSubscriptionTopics" : [ ],

    "recentPublishTopics" : [ ],

    "preDefinedMessages" : [ ],

    "brokerAddress" : "contoso.azure-devices.net",

    "brokerPort" : "8883",

    "lastPublishTopic" : null,

    "lastSubscriptionTopic" : null,

    "profileName" : "MyDevice01@Contoso",

    "scriptsPath" : "",

    "connectionOptions" : {

      "clientId" : "paho398791429784759",

      "connectionTimeout" : 30,

      "keepAliveInterval" : 60,

      "mqttVersionUseDefault" : true,

      "mqttVersion" : "3.1.1",

      "cleanSession" : true,

      "userName" : "contoso.azure-devices.net/MyDevice01",

      "password" : "SharedAccessSignature sr={your hub name}.azure-devices.net%2fdevices%2fyDevice01&sig=vSgHBMUG.....Ntg%3d&se=1456481802g%3d&se=1456481802",

      "lwtQos" : 1,

      "lwtRetained" : false,

      "lastWillDestination" : "devices/MyDevice01/messages/events/dead",

      "testament" : "",

      "useProxy" : false,

      "useHttpsProxy" : false,

      "httpsProxyHost" : "",

      "httpsProxyPort" : "",

      "httpProxyHost" : "",

      "httpProxyPort" : "",

      "httpProxyUser" : "",

      "httpProxyPassword" : "",

      "enableSSLTLS" : true,

      "sslTlsProtocol" : "TLSv1.2",

      "certificateFilesPemFormat" : false,

      "selfCreatedCaFile" : "",

      "caFile" : "",

Hi kafouros​,

When I test using mosquitto, I must set --capath /etc/ssl/certs/  otherwise the connection fails.

I'm wondering how you connect with "caFile":""?

0 Likes