# ThingsPro 2.5 Application: Azure
:::danger
For Internal Use Only–Not for Pubic Distribution.
:::
> [name=Anthony Ho, MUS Applications Engineer]
###### tags: `Azure` `ThingsPro` `Application`
## Objective
This application note will demonstrate how ThingsPro 2.5+ is used to publish data to Azure Iot Hub with Azure Stream Analytics for data processing to enable users to develop and run real-time analytics on multiple streams of data from sources like sensors.
## Prerequisites
- ThingsPro 2.5 or greater
- Azure
- IoT Hub, IoT device connection string
- Stream Analytics
## Azure
### Testing/Debugging (Optional)
This section demonstrates how to use `Azure Cloud Shell` to quickly monitor the data that is being sent to IoT Hub by executing the following Azure CLI command.
```bash
$ az iot hub monitor-events -n Moxa-GMKT-IoTHub --content-type application/json
```
The format of the data should like similar to this:
```json
{
"event": {
"origin": "MoxaTestStream",
"payload": {
"deviceName": "veris",
"timestamp": "2019-07-26T23:30:22Z",
"tags": [
{
"Name": "Accumulated_Real_Energy",
"Value": 2755800.0
},
{
"Name": "Real_Energy_Import",
"Value": 2772915.0
}
]
}
}
}
```

:::info
More info on Azure CLI can be found [here.](https://docs.microsoft.com/en-us/cli/azure/ext/azure-cli-iot-ext/iot/hub?view=azure-cli-latest#ext-azure-cli-iot-ext-az-iot-hub-monitor-events)
:::
### Stream Analytics
If the data exists in Iot Hub, ``Azure Stream Analytics`` will be used to process and parse the data with query statements. The query example below is a demonstration on how to acquire the data from the payload along with origin (DeviceId).
```sql
WITH iothubdata AS
(
SELECT *, GetMetadataPropertyValue(iothub, 'IoTHub.ConnectionDeviceId') AS DeviceId FROM iothub
),
RealEnergyImport AS
(
SELECT *
FROM iothubdata
)
SELECT * INTO MoxaTest2 FROM RealEnergyImport
```

To parse a specific data, select the desired object for monitoring. The following example demonstrates how to acquire ``DeviceId``, ``deviceName``, ``timestamp``, and ``value`` for ``Real_Energy_Import`` for the output.
```sql
WITH iothubdata AS
(
SELECT *, GetMetadataPropertyValue(iothub, 'IoTHub.ConnectionDeviceId') AS DeviceId FROM iothub
),
RealEnergyImport AS
(
SELECT
iothubdata.DeviceId,
iothubdata.deviceName,
CAST(iothubdata.timestamp AS datetime) as timestamp3,
arrayElement.ArrayValue.Value
FROM iothubdata
CROSS APPLY GetArrayElements(iothubdata.tags) AS arrayElement
WHERE arrayElement.ArrayValue.Name = 'Real_Energy_Import'
)
SELECT * INTO MoxaTest2 FROM RealEnergyImport
```


:::success
As you can see, the desired data is nicely parsed out. The outputs can be used with services like Azure Data Lake Storage Gen 1 and/or Power BI. More information on understanding outputs from Azure Stream Analytics can be found [here](https://docs.microsoft.com/en-us/azure/stream-analytics/stream-analytics-define-outputs).
:::