# How to send data to Azure IoT Hub

![](https://2165942204-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MMKXTFIN5ZlLOjBlfC4%2F-MjYCYRcDoPLgbqvsnc1%2F-MjYDLx6J_aF-QiTzauY%2Fimage.png?alt=media\&token=abb40d03-757c-4222-b0d4-07f42f893f02)

{% hint style="success" %}
**Benefits of the Azure IoT Hub output connector**:

* Directly stream device data from akenza to **Azure** and subsequently process it in [Azure services](https://azure.microsoft.com/en-us/services/)
* Easily process **low-power device** data e.g. LoRaWAN device data in a **Microsoft service**
  {% endhint %}

In this tutorial, you will learn, how to send data to **Azure IoT Hub**. The following steps are explained in more detail:

1. [Setup an **Azure IoT Hub**](#1.-setup-an-azure-iot-hub)
2. [Obtain an Azure IoT Hub **connection string**](#2.-obtain-an-azure-iot-hub-connection-string)
3. [Setup a **Data Flow** in akenza ](#3.-setup-a-data-flow-in-akenza)
4. [Monitor events](#4.-monitor-events)
5. [Use of further Azure services](#5.-use-of-further-azure-services)
6. [Useful Links](#6.-useful-links)

### 1. Setup an Azure IoT Hub

First, you will need to [set up an Azure IoT Hub](https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-create-through-portal) in order to successfully process data from akenza in Azure services.

#### 1.1 Create an IoT Hub resource

* Sign in to the [Azure portal](https://portal.azure.com/)
* Create a new Azure IoT Hub resource, by selecting ***+ Create a resource***, and then entering *IoT Hub*
* Assign a *resource group* by choosing an existing group or creating a new one and fill the *IoT hub name* and *region* fields; choose *Public access* in the networking tab to select a *tier* that fits your use case in the Management tab (use the free tier for testing)
* Select *review and create* to provision the IoT hub resource

#### 1.2 Add a shared access policy

* Navigate to your IoT Hub resource and select *Shared access policies* in the *Settings* section
* Select *+ Add shared access policy***,** give a name and check *all boxes* for the permissions (registry read, registry write, service connect, and device connect permissions)

![Adding a shared access policy](https://2165942204-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MMKXTFIN5ZlLOjBlfC4%2F-MjnUBMrnHTWWgMykaca%2F-MjnVFGjtSElmLlj4b2g%2Fimage.png?alt=media\&token=6e4ffe96-0dd7-4f22-8c64-b32bc5dd7930)

### 2. Obtain an Azure IoT Hub **connection string**

Once the policy is created, obtain the *Primary Connection String*, by clicking the policy and copying the connection string. The connection string will be used to create the connector in akenza.

![Obtaining the connection string](https://2165942204-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MMKXTFIN5ZlLOjBlfC4%2F-Mjmmw_0J0rbyIOGc6NJ%2F-Mjmqos8AuI4Gnwuwjb5%2FScreenshot%202021-09-17%20at%2010.23.33.png?alt=media\&token=e9875640-9419-4d39-9b4f-e324f9a0d599)

### 3. Setup a Data Flow in akenza

Create a new **Data Flow** with **Azure IoT Hub** as output connector. Define a **Connector Name** and insert the **Connection String** obtained from the shared access policy.

![Azure IoT Hub template](https://2165942204-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MMKXTFIN5ZlLOjBlfC4%2Fuploads%2Fxlf7Xlenm5k9TSyDC1s9%2Fscreely-1640896936345%20azure.png?alt=media\&token=c3aa2cb7-faf3-4c67-b04f-9c64b3164fe8)

[Create a new device](https://docs.akenza.io/akenza.io/how-to-create-a-working-environment/how-to-connect-a-device) using the Data Flow and start sending data.

{% hint style="info" %}

* The whole data sample will be forwarded to Azure IoT Hub
* If a device sends data and does not yet exist in the registry of IoT Hub, it will be automatically created
  {% endhint %}

### 4. Monitor Events

In order to monitor uplinks that are sent to Azure IoT Hub, you can use Azure CLI with the [Azure IoT CLI Extension](https://github.com/Azure/azure-iot-cli-extension). Use the following commands to install the extension and monitor incoming uplinks:

```
az extension add --name azure-iot
az iot hub monitor-events -n <azure-iot-hub-name> --login <azure-iot-hub-connection-string>
```

{% hint style="info" %}
All devices which have sent data can be inspected in the *IoT Device Explorer* on *IoT Hub*.
{% endhint %}

![IoT Device Explorer on IoT Hub](https://2165942204-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MMKXTFIN5ZlLOjBlfC4%2F-MjYIJpQdnd4NsP4epdu%2F-MjYdhUUdvesKXUlBylk%2Fscreely-1631611784878_azure_devices.png?alt=media\&token=a86cb732-8d6a-4b33-9652-9bb50feed941)

### 5. Use of further Azure services

Once a device is connected to the IoT Hub, device data can be further used on various **Azure services:**

{% hint style="success" %}
**Possible services are:**

* [Stream Analytics](https://azure.microsoft.com/en-us/services/stream-analytics/)

  Real-time data stream processing
* [Machine Learning](https://azure.microsoft.com/en-us/services/machine-learning/)

  Powerful cloud-based predictive analytics tool to enable predictive maintenance
* [Notification Hubs](https://azure.microsoft.com/en-us/services/notification-hubs/)

  A scalable, push notification engine for quickly sending messages
* [Power BI](https://powerbi.microsoft.com/en-us/)

  A suite of business analytics&#x20;
  {% endhint %}

### 6. Useful Links

* [akenza Azure IoT Hub connector](https://docs.akenza.io/akenza.io/get-started/your-data-flow/connectors/streaming/azure-iot-hub)

{% embed url="<https://docs.microsoft.com/en-us/azure/architecture/reference-architectures/iot>" %}

{% embed url="<https://docs.microsoft.com/en-us/azure/iot-hub/>" %}

{% embed url="<https://docs.microsoft.com/en-us/azure/iot-hub/tutorial-routing#route-to-a-storage-account>" %}

{% embed url="<https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-vscode-iot-toolkit-cloud-device-messaging>" %}

{% embed url="<https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-live-data-visualization-in-power-bi>" %}
