Cloud Export with History Transfer Controller (MQTT Publisher)

This page illustrates how to configure a History Transfer Controller object (instead of the Cloud Sink object) to export history data to an MQTT broker or, to be more specific, to the Azure IoT Hub to which we already connected using the Cloud Sink with Azure IoT Hub. We will also use the same Sample MQTT Broker .

For information regarding the general configuration of the History Transfer Controller, see the Object Guide.

Requirements

To be able to follow this guide, you will need:

  • Microsoft Azure account with a valid subscription and all the necessary permissions to add and manage resources. There also should be at least one Resource Group. More information about Resource Groups is available on the official Microsoft Documentation webpage.

  • access to an Azure IoT Hub. The configuration of a sample IoT Hub for testing purposes is described here.

  • an IoT Device in the aforementioned Azure IoT Hub, with SAS Token Authentication configured.This page addresses how to create such a device, where to set or find the Device ID and how to generate a SAS Token.

  • the Device ID and a generated SAS Token for the aforementioned IoT Device.

Configuration

1 Create a new History Transfer Controller object.

2 Select the newly created History Transfer Controller object and open the Object Lens.

3 Specify the tags for which you want to export history data as described in the section on Specifying the Objects for Data Export of the Data Export page in the History Transfer Controller Object Guide.

4 Expand the Sink Configuration property compound, …​

  • For the Node property, specify the path to the egress Node object.

  • Enter an Object Name for the History Sink and

5 Expand the Configuration sub-compound.

  • For Interface select the MQTT Publisher option.

6 Expand the MQTT Publisher Parameters sub compound.
The configuration entered here should match the IoT device parameters created in the Azure IoT Hub setup.

  • For the Topic property, enter a string following this pattern:

     devices/<DEVICEID>/messages/events/

    where <DEVICEID> refers to the Device ID from the Requirements.
    In this example the device ID is “inmIoTDevice01” so the Topic property becomes: 'devices/inmIoTDevice01/messages/events/'.'

  • For the Quality Of Service property, enter 1. This means the publisher will wait for confirmation from Broker that it received a message.

7 In the Connection Parameters sub-compound:

  • For the Client ID property, enter the Device ID from the Requirements (device ID = “inmIoTDevice01”).

  • For the Broker Port property, enter 8883 and

  • For the Broker Address property, enter a string following this pattern:

    <HUBNAME>.azure-devices.net

    where <HUBNAME> referst to the name of the Azure IoT Hub. In this example the hub is called inmIoTHubFree, so the Broker Address property becomes 'inmIoTHubFree.azure-devices.net'.

8 Open the Credentials sub-compound.

  • For the Username property enter a string following this format:

    <HUBNAME>azure-devices.net/<DEVICEID>/?api-version=2018-06-30

    So in this example it becomes 'inmIoTHubFree.azure-devices.net/inmIoTDevice01/?api-version=2018-06-30'.

  • For the Password property, enter the SAS Token from the Requirements.

9 Open the SSL/TLS Support sub-compound.

  • For the Certificate Authority property, enter the DigiCert Baltimore Root Certificate mentioned in the Requirements.

Starting the Data Transfer

1 To begin the history export immediately, go back to the Common property compound and

  • Switch the Processing Mode from "Configuration" to "Operation" and click Apply to begin the data transfer.

Checking Functionality

1 To check on the progress of the MQTT History Sink export, go to the Diagnostics property compound of the History Transfer Controller.

  • the Process State property shows when the next message will be sent to the History-Sink

  • the Recent Data Size indicates how large the last message was

  • the UTD-Values property shows how many data points have been written

The History Transfer Controller should also show a green light in the I/O Model.

2 Select the History Sink object in the I/O Model (which is located underneath the Node object specified in the Sink Configuration > Node property of the History Transfer Controller configuration).

3 In the Object Lens, open the Diagnostics property compound for the selected History Sink object to check the status of the most recent export.

The progress can also be followed by using Visual Studio Code and installing the IoT Azure Hub extension.

Smart Message Configuration

MQTT has a maximum message size of 256 KB. Depending on the amount of data you transfer, it can easily happen that the JSON messages get larger the 256 KB. It is possible to use the Smart Messages feature to split up the messages automatically. Using Smart Messages, you can also prepare different JSON formats.

1 To do this, open the Sink Configuration property compound on the History Transfer Controller and go to Advanced Options > Transfer Processing and for the Smart Messages property enter "Flat JSON".

2 Click Apply and check the properties in the Diagnostics compound to see when the first messages have been sent.

3 If Using Visual Studio Code and the IoT Azure Hub extension,you can monitor the endpoint and confirm that messages are received.

The Flat JSON format is ideal for ingesting the data in Azure Time Series Insights.