---
title: Send Data to Azure IoT Hub with an SAS Key
slug: bhdo-v3/send-data-to-azure-iot-hub-with-an-sas-key
createdAt: 2022-11-24T18:16:59.000Z
---

Review the following guide for setting up an outbound data integration between Belden Horizon Data Operations and Azure IoT Hub using an SAS key.

# Before You Begin

You must first [Set up an Azure IoT Hub](docId\:pMS3cnFw5k2cBsuEeR8PU).&#x20;

# Step 1: Add a Device in Belden Horizon Data Operations

Follow the steps to [Connect a Device](docId\:T-cWPe0_Jsfw5-aoj8WPP). The device will be used to store tags that will be eventually used to create outbound topics in the connector. Make sure to select the **Enable Data Store** check box.&#x20;

# Step 2: Add Tags

After connecting the device in Belden Horizon Data Operations, you can [Add Tags](docId\:Wpe2HMXelARLBnhWbuChY) to the device. Create tags that you want to use to create outbound topics for the connector.&#x20;

# Step 3: Add the Azure IoT Hub Using SAS Key Connector

Follow the steps to [Add a Connector](docId\:ORxib_vla2NGvDx94Z1ow) and select the **MQTT - Azure IoT Hub using SAS Key** provider.&#x20;

Configure the following parameters.&#x20;

- **Name**: Enter a name for the connector.&#x20;
- **Hostname**: The IP address or server FQDN of the MQTT broker (must be reachable from your edge device).&#x20;
- **Port**: The MQTT broker's port number. The default value is 8883.&#x20;
- **Device ID**: Copy the **Device ID** of your edge device from th&#x65;*&#xA0;IoT Devices* page in the Azure portal and paste it here.
- **SAS Key**: Copy the primary or secondary shared access key from the *IoT Devices* page in the Azure portal and paste it here.&#x20;
- **Parallel Publish Count**: The maximum number of concurrently published messages. The default value is 16.&#x20;
- **Integration Topic**: The default topic to publish or subscribe to: devices/\[deviceId]/messages/events/. Replace `[deviceId]` with the Device ID copied from Azure.&#x20;
- **Token TTL**: The token expiry time in minutes. The default value is 1440.&#x20;
- **LWT Topic**: The topic for MQTT's Last Will and Testament feature.&#x20;
- **LWT payload**: The payload for MQTT's Last Will and Testament feature.&#x20;
- **LWT payload type**: The payload type for MQTT's Last Will and Testament feature. The options are *string&#x20;*&#x61;nd *base64*.&#x20;
- **LWT QoS**: The Quality of Service value for MQTT's Last Will and Testament feature.&#x20;
- **LWT retained**: Select this check box to retain the value for MQTT's Last Will and Testament feature.&#x20;
- **Throttling Limit**: The maximum number of messages per second to be processed. The default value is zero, which means that there is no limit.&#x20;
- **Persistent storage**: When enabled, this will cause messages to undergo a store-and-forward procedure. Messages will be stored within Belden Horizon Data Operations when cloud providers are online. &#x20;

# Step 4: Enable the Connector



::Image[]{src="https://api.archbee.com/api/optimize/vAqK-046vdh4I0e1y9cfX/BcrwsDaxu_hVkgRd1EW_B_azureiotsas.png" size="60" width="370" height="345" position="center" showCaption="false"}

# Step 5: Create Outbound Topics for Connector

You will now need to create topics from the tags you added in Step 2. &#x20;

Before creating the topics copy the *Raw Topic* parameter for all tags you want to use for topics. See [Manage Tags](docId\:NRpE2visWYDkGEcoSWzQ0) for more information.

**To create topics:**

1. Click the connector tile.
   The connector *Dashboard&#x20;*&#x61;ppears.&#x20;
2. Click the **Topics&#x20;**&#x74;ab.&#x20;
3. Add topics to the connector with the details below. See the *Add a Topic to a Connector* section in [Manage Connectors](docId\:oCBQwYcY_xmMKWV9AUNQ-) for more information.&#x20;
   - **Data Direction**: Select **Local to Remote - Outbound**.&#x20;
   - **Local Data Topic**: Paste th&#x65;*&#x20;Raw Topic* for the tag created in Step 2.&#x20;
   - **Remote Data Topic**: Verify the format of the remote data topic is **devices/\[DeviceID]/messages/events/**. Replace \[DeviceID] with the Device ID parameter configured for the connector.  **devices/MyDevice/messages/devicebound/%24.to=%2Fdevices%2Fmessages%2Fdevicebound**.
   - **Enable**: Click the toggle to enable the topic.&#x20;
4. Click **Yes&#x20;**&#x74;o add the topic.&#x20;
5. After adding all required topics, navigate to the *Integration&#x20;*&#x70;ane and ensure the connector shows a *Connected&#x20;*&#x73;tatus.&#x20;

# Step 6: Create TestTable and Mapping

**To create a TestTable and mapping:**

1. Log in to the Azure portal
2. Open the device pane&#x20;
3. Click the **IoT Hub&#xA0;**&#x6C;ink, and then click the **DataPub&#xA0;**&#x6C;ink.
4. Scroll down to display the IoT messages.
5. Click the **Home&#xA0;**&#x6C;ink, and then click **Azure Data Explorer**.
   The *Azure Data Explorer Clusters* pane appears.
6. Click the **clusterduck&#xA0;**&#x6C;ink.
   The *clusterduck&#xA0;*&#x70;ane appears.
7. From the right pane, click **Query**.
   The *Query&#x20;*&#x70;ane appears to the right.
8. Click **testdb**.
   The `.create table TestTable (temperature: string); `line appears.
9. Click **Run**.
   The TestTable schema appears below and TestTable appears beneath testdb.
10. Replace `.create table TestTable (temperature: string);` with `.create table TestTable Ingestion json mapping 'mapping' '[{"column":"temperature","path":"$","datatype":"string"}]';`, and then click **Run**.
    The mapping json appears below.
11. Click the **Expand&#x20;**&#x69;con next to *TestTable&#x20;*&#x74;o reveal *temperature (string)*.&#x20;

    ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/ch6sNG3YhKe3SWXDs44ZV_azure-testtable-mapping.png" size="80" width="681" height="321" caption="The temperature string parameter" position="center" showCaption="true"}

# Step 7: Add a Data Connection in Azure

**To add a data connection in Azure:**

1. On the Azure home page, from the left navigation pane under **Data**, click **Databases**.
2. Click the **testdb&#xA0;**&#x6C;ink.
   The *testdb&#xA0;*&#x70;ane appears.
3. From the left pane, click **Data Ingestion**.
   The *Data Ingestion* pane appears.
4. From the right pane, click **Add data connection**.
   The *Data connection* pane appears to the right.
5. From the **Select connection type&#xA0;**&#x64;rop-down listm select **IoT Hub**.
   The *IoT Hub* dialog box drops down.
6. From the *IoT Hub* dialog box, enter **conn&#x20;**&#x69;n the **Data connection name&#xA0;**&#x66;ield.
7. From the **Iot Hub** drop-down list, select **DataHub**.
8. From the **Shared Access Policy&#xA0;**&#x64;rop-down list, select **iothubowner**.
9. From the **Consumer group** drop-down list, select $**Default**.
10. In the **Table&#x20;**&#x66;ield, enter **TestTable**.
11. From the **Data format&#xA0;**&#x64;rop-down list, select **JSON**.
12. In the **Column mapping** field, enter mapping.
13. Click **Create**.
    The data connection appears in the *Data Connection* list.
14. From the left Navigation panel, click **Query**.
    The *Query&#xA0;*&#x70;ane appears.
15. Enter **SELECT \* FROM TestTable;&#xA0;**&#x69;n the query line, and then click **Run**.
    The values for TestTable appear below.

    ![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/3eSQL9nS5dphSSxbo4tXV_azure-query.png "Values for TestTable")

