Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Easy Heading Macro
headingIndent40
navigationTitleOn this page
selectorh2,h3
wrapNavigationTexttrue
navigationExpandOptiondisable-expand-collapse

...

iconfalse
titleIntroduction

...

For more information on these topics, see MQTT Protocol and Introduction to Microsoft IoT Hub.


Info
iconfalse

Quick video tutorial (no audio)


System Requirements

Below is listed the The requirements for a successful configuration .of MQTT and Azure are listed below:

  • MQTT Driver version 0.2.1;
  • Microsoft Azure IoT Hub Account;
  • Visual Studio Code with an Azure IoT Hub


...

Configuration Settings

...

Visual Studio Code

Visual Studio Code is an open-source, streamlined code editor with support for development operations like debugging, task running, and version control. It  Visual Studio Code can be downloaded here.

To download the extension that allows interaction with interactions to Visual Studio, Azure IoT Hub, and IoT Device Management, click here.

Note

This guide assumes that an IoT Hub already exists within the Azure Portal account.

...

After installing the extension, open the VSCode application. In Explorer the explorer pane of the VS Code, click the ”Azure IoT Hub” tab in the bottom left corner (1 below), and Click click ”Select IoT Hub” (2) in the context menu.

If you have are not signed in to into Azure, a pop-up will show appear in the bottom right corner to let prompt you sign in to Azure (3).

Azure IoT Extension Setup.


After you sign in, your Azure Subscription list will be shown, then select Your Azure Subscription list will appear after you sign in. Select the Azure Subscription and IoT Hub. The After a few seconds, devices and endpoints list will be shown appear in ”Azure the Azure IoT Hub” Hub tab in a few seconds. 

Devices in IoT Hub.


New IoT Devices can be created through this the Azure IoT Hub extension. From Select the context menu (1 below), click on Create Device (2), and enter a Device ID for the new IoT device. 


Device creation.


Now that we have our Devices your device is created, we will you need to get our setup your Connection String and SAS Token. 

To do this, right click on your device and select Get Device infoRight-Click on the Device and select ”Get Device Info”. You should see some information displayed at in the Output Windowoutput window. 

Connection String.


Review the Connection String that was created for the device and record the following pieces of information from this string:

Code Block
HostName = TatsoftTestHub.azure-devices.net DeviceId = NewDevice


Again, right-Right click on the device and , select ”Generate Generate SAS token Token for device” Iot Hub, and enter the expiration time. You should see some the information displayed at in the Output Windowoutput window. 

SAS Token.


Record the following pieces of information from this string:

...

To verify that data is flowing from the MQTT Driver to the cloud-based Azure IoT Hub, right - click on the device entry and select ”Start Monitoring Built-In Event Endpoint”. 

Enable Device Endpoint.


MQTT Driver

On In your Project’s project’s Engineering Environmentenvironment, navigate to Devices > Channels and add a new MQTT channel by selecting it from the Installed Protocols menu.

MQTT Channel creation.


On In Devices > Nodes, add a node for the newly created MQTT Channel. The Primary Station primary station's configuration is done made as follows:

Code Block
URL = <Host Name> Port = <Port Number>
Client ID = <Device Id>
Username = <Host Name>/<Device Id> Password = <SAS Token>
TLS Version = <TLSv1.0>
X059 Certificate = <Certificate thumbprint>  (optional)  QoS = <Quality of Service>
Keep Alive = <Message sent to Broker to prevent the link from being broken> (in seconds)


For our the IoT Hub and Device the device configured in VSCode, the parameters are as follows.

Code Block
URL = TatsoftTestHub.azure-devices.net Port = 8883
Client ID = NewDevice
Username = TatsoftTestHub.azure-devices.net/NewDevice
Password = SharedAccessSignature sr=TatsoftTestHub.azure-devices.net&sig=pzzXCZK%2 BQ6dJUe2Hf1SptTR1oPMbfyip0K9M4TQPZc4%3D&skn=iothubowner&se=1593008673

TLS Version = <TLSv1.0> X059 Certificate =
QoS = AtMostOnce Keep Alive = 1


MQTT Node creation.


Lastly, on Finally, in Devices > Points, fill in the Address address information is filled according to the syntax below:

Code Block
devices/<Device Id>/messages/events/

For our this example device, the correct topic is:

Code Block
devices/NewDevice/messages/events/


MQTT Point creation.


Once the Device device configuration is complete, go to Run > Startup and execute the project. Open Enable the Trace Window (with Debug and Devices options enabled) and by clicking on settings and selecting the corresponding boxes. Open the TraceWindow and monitor the communication exchange.

Trace Window logs.


Back on VSCode, you can should see the received messages on in the Output Windowoutput window.

Messages received in VSCode.