Overview
MQTT is a standard protocol, but there are extensions of the specification that different manufacturers may implement or not. Therefore, the platform has additional MQTT drivers to accommodate the variations used by those suppliers.
Currently, the following MQTT communication drivers are available:
- MQTT Message Queueing Telemetry Transport: standard protocol.
- MQTT SparkplugB Protocol: Implements SparkplugB extensions.
- MQTT for Azure IoT Hub: Integrates with Microsoft Azure IoT Hub.
- MQTT Weg - Message Queueing Telemetry Transport: Integrates with Weg IoT platform.
On this page:
Table of Contents | ||||
---|---|---|---|---|
|
Azure IoT Hub is a managed cloud service that acts as a central message hub for bi-directional communication between IoT applications and their connected devices. It facilitates secure, reliable connectivity for millions of devices, supporting messaging patterns such as device-to-cloud, cloud-to-device, and file upload from devices.
The software platform integrates with Azure IoT Hub and other Azure services for enhanced IoT solutions, enabling real-time analytics, machine learning, business process automation, and event-driven responses. The Azure IoT Hub offers scalable solutions for device management, data analysis, and integration with enterprise systems.
On this page:
Table of Contents | ||||
---|---|---|---|---|
|
For more information on these topics, see MQTT Protocol and IoT concepts and Azure IoT Hub.
Info | ||
---|---|---|
| ||
System Requirements
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. Visual Studio Code can be downloaded here.
1. To download the extension that allows 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. |
2. After installing the extension, open the VSCode application. In the explorer pane of the VS Code, click the ”Azure IoT Hub” tab in the bottom left corner (1), and click ”Select IoT Hub” (2) in the context menu.
If you are not signed into Azure, a pop-up will appear in the bottom right corner to prompt you sign in to Azure (3).
3. Your Azure Subscription list will appear after you sign in. Select the Azure Subscription and IoT Hub. After a few seconds, devices and endpoints will appear in the Azure IoT Hub tab.
4. New IoT Devices can be created through the Azure IoT Hub extension. Select the context menu (1), click Create Device (2), and enter a Device ID for the new IoT device.
5. Now that your device is created, you need to setup your Connection String and SAS Token.
Right-click on your device and select Get Device Info. You should see information displayed in the output window.
6. 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 |
7. Right-click on the device, select Generate SAS Token for Iot Hub, and enter the expiration time. You should see the information displayed in the output window.
8. Record the following pieces of information from this string:
Code Block |
---|
Password = SharedAccessSignature sr=TatsoftTestHub.azure-devices.net&sig=pzzXCZK%2 BQ6dJUe2Hf1SptTR1oPMbfyip0K9M4TQPZc4%3D&skn=iothubowner&se=1593008673 |
9. To verify that data is flowing from the MQTT Driver to the cloud-based Azure IoT Hub, right-click on the device and select Start Monitoring Built-In Event Endpoint.
MQTT Driver
1. In your project’s Engineering environment, go to Devices → Channels and add a new MQTT channel by selecting it from the Installed Protocols menu.
2. In Devices → Nodes, add a node for the newly created MQTT Channel. The primary station's configuration is performed 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) |
3. For the IoT Hub and 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 |
4. Finally, onDevices → Points, fill in the address information according to the syntax below:
Code Block |
---|
devices/<Device Id>/messages/events/ |
For this example device, the correct topic is:
Code Block |
---|
devices/NewDevice/messages/events/ |
5. Once the device configuration is complete, go to Run → Startupand execute the project. Enable the Debug and Devices options by clicking on settings and selecting the corresponding boxes. Open the TraceWindow and monitor the communication exchange.
6. Back on VSCode, you should see the received messages in the output window.
In this section:
Page Tree | ||||
---|---|---|---|---|
|