11 Replies Latest reply on Jan 15, 2017 7:52 PM by axel.lin_1746341

    MQTT Last will and testament support

    kafouros

      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.

        • 1. Re: MQTT Last will and testament support
          axel.lin_1746341

          Hi,

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

           

          Thanks,

          Axel

          • 2. Re: MQTT Last will and testament support
            kafouros

            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

            2 of 2 people found this helpful
            • 3. Re: MQTT Last will and testament support
              axel.lin_1746341

              I'm referencing below doc:

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

               

              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.

              • 4. Re: MQTT Last will and testament support
                kafouros

                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" : "",

                      "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.

                2 of 2 people found this helpful
                • 5. Re: MQTT Last will and testament support
                  mifo

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

                   

                  Thanks for the help.

                  • 6. Re: MQTT Last will and testament support
                    suchitra.hullur

                    Is LWT supported in  v3.7.0?

                    • 7. Re: MQTT Last will and testament support
                      axel.lin_1746341

                      suchitra.hullur wrote:

                       

                      Is LWT supported in  v3.7.0?

                      No.

                      • 8. Re: MQTT Last will and testament support
                        kafouros

                        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.

                        1 of 1 people found this helpful
                        • 9. Re: MQTT Last will and testament support
                          suchitra.hullur

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

                          • 10. Re: MQTT Last will and testament support
                            axel.lin_1746341

                            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).

                            • 11. Re: MQTT Last will and testament support
                              axel.lin_1746341

                              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":""?