MQTT Datasource
This section will show you how to create and configure a MQTT Datasource. The MQTT Datasource enables you to connect to an MQTT server and subscribe to messages communicated using the MQTT messaging protocol.
For this example we will connect to an Azure IoT Hub that is configured to support MQTT communication. For instructions on how to set this up, please visit the Cloud Sink with Azure IoT Hub. |
Both SAS Token Authentication and X.509 CA Certificate Authentication are supported but in this example we will show how to configure for SAS Token Authentication.
Configuration of MQTT Datasource
-
In DataStudio, first create a local Connector. Then, select the Connector, right-click from the Context menu add a new datasource. In the Create Object wizard, go to the Server Type page, select "MQTT" from the drop-down menu and enter "MQTT" as the Subscriber Name. Click Create to create the Datasource.
Figure 1. Create MQTT Datasource - Server Type -
Select the Datasource in the I/O Model and go to the Connection Parameters property compound. These should be entered as described in the Cloud Sink with Azure IoT Hub instructions. The Broker address is of the form:
[Hub name] + .azure-devices.net
For this specific example, the Broker Port is set to "8883" and the Client ID to "indevice".
Figure 2. MQTT Datasource - Connection Parameters -
In the Credentials property compound enter the Username and the generated SAS Token. The Username should be of the form:
[Hub name] + .azure-devices.net + [Device ID] + /?api-version=2018-06-30
Figure 3. MQTT Datasource - Connection Parameters -
Open the SSL/TLS Support property compound and enter the path to a DigiCert Baltimore Root certificate. For details on how to obtain this follow the instructions here.

-
To subscribe to a topic click on the "+" in the Subscription Data property compound and set Topic as "#" (this means subscribe for the complete tree of topics available on the broker), and Quality Of Service as "0".

For subscriptions, two wildcard characters are supported
For this example imagine that broker has 4 topics: SENSOR/1/TEMP, SENSOR/1/HUMIDITY, SENSOR/2/TEMP, SENSOR/2/HUMIDITY. - """ character represents a complete sub-tree of the hierarchy and thus must be the last character in a subscription topic string. Example: SENSOR/1/ This will match any topic starting with SENSOR/1/, such as SENSOR/1/TEMP and SENSOR/1/HUMIDITY. - "+ character represents a single level of the hierarchy and is used between delimiters. Example, SENSOR/+/TEMP This will match SENSOR/1/TEMP and SENSOR/2/TEMP. |
A successful connection is indicated by both state and communication indicators being green. This also means that Datasource has successfully subscribed to all specified topics and now is waiting for notifications.
Receiving Messages
To check that you are receiving messages, you can firstly check in the Azure IoT Portal by going to
in the portal.
Alternatively, you can use the Visual Studio Code extension to send messages to the device. Select the device in the list and use Send C2D Message to Device from the context menu.


The message can now be seen in Data Studio.

And in the Faceplate of the item.
