Power IoT: Leverage Azure IoT and Power BI

by Dominik Deschner
Power IoT: Leverage Azure IoT and Power BI

Introduction

Azure IoT enables us to swiftly connect IoT devices to our cloud solutions, allowing us to measure, transmit, and process various data types, such as environmental data. Visualization plays a pivotal role in most IoT use cases, often being essential in early Proof of Concepts (PoCs) to offer stakeholders a functional visual representation. In this article, I'll demonstrate how you can harness the capabilities of Azure IoT Hub, Azure Stream Analytics, and Power BI to quickly construct advanced dashboards using your IoT data.

Setup simulated IoT device

For this demonstration, we'll utilize the excellent Device Telemetry Simulator provided by Microsoft. If you prefer not to run the Docker image, you are welcome to build and run the tool from its source; the configuration will remain equivalent. Before we begin, let's create a new device in our IoT Hub, as demonstrated below.

Create new iot device in IoT Hub
Create new iot device in IoT Hub

Before we can begin the simulation, we need to obtain the ConnectionString for our new device. Copy it to the clipboard as demonstrated below. Ensure that you remove the DeviceId from the connection string before setting the environment variables, as shown below.

Copy primary connection string
Copy primary connection string

Remove the DeviceId from the connection string before you set the environment variables like shown below. 

Starting the simulator
Starting the simulator

Insert your own ConnectionString and modify the DeviceList parameter to correspond to your device name. It's crucial to set the DeviceList parameter to your device name, allowing the simulator to identify the device to be simulated.

docker run -it -e "IotHubConnectionString=<>" mcr.microsoft.com/oss/azure-samples/azureiot-telemetrysimulator -e "DeviceList=poweriot" -e "MessageCount=0"

Afterward, we can utilize the fantastic Azure IoT Explorer to confirm that the simulator is transmitting data. As demonstrated below, we'll receive messages containing a 'counter' field in the body, which increments with each subsequent message.

Simulated message generated with the simulator
Simulated message generated with the simulator

Create a Power BI workspace

To structure our dashboards and data sources, let's establish a new workspace in Power BI. Access Power BI, click on the workspace tile, and follow the steps below to add a new workspace, as illustrated.

Dialogue to create a new workspace in Power BI
Dialogue to create a new workspace in Power BI

Next, we should extract the workspace ID by navigating to the newly created workspace. The URI in your browser should match the following pattern:

https://app.powerbi.com/groups/<workspaceId>/

Copy and take note of the workspace ID to connect our data source in the subsequent step.

Connecting the dots with Stream Analytics

Stream Analytics is a potent service within the Azure platform as it enables the joining and aggregation of asynchronous data streams from diverse sources, directing them to various services. These capabilities particularly benefit IoT use cases. In this section, we'll establish a Stream Analytics task that subscribes to our IoT hub and directly routes the data to Power BI. Let's initiate by creating a new Stream Analytics job, as illustrated in the image below.

Creating a new stream analytics job
Creating a new stream analytics job

Ensure to adjust the streaming units according to your needs. For demonstration purposes, I've set it to the lowest possible value. Once the task has been successfully deployed, we can proceed by adding the IoT Hub as a data source.

Add IoT Hub input source
Add IoT Hub input source
Add IoT Hub input source
Add IoT Hub input source

Next let's add in a similar way our Power BI workspace as a data sink.

Add Power BI as output
Add Power BI as output

In the next step we need to enter the saved workspace id from Power BI and add it to the field "Group workspace"

Configure Power BI connection
Configure Power BI connection

We've completed the major setup, and now we can create a query to extract data from the IoT Hub and direct it to Power BI. The query editor should generate a very similar query for you by default. Feel free to add additional data sources and customize the query as per your requirements. To preview the output of your query, run "Test query". Once satisfied, save the query and initiate the job by clicking the "Start job" button.

Stream analytics query editor
Stream analytics query editor

After starting the job, you'll notice a new streaming dataset added to our Power BI workspace. This dataset enables us to generate reports and dashboards using our IoT data.

IoT data source in Power BI
IoT data source in Power BI
IoT data source in Power BI
IoT data source in Power BI

Conclusion

In conclusion, leveraging Azure IoT services, including Azure IoT Hub, Stream Analytics, and Power BI, allows for the seamless integration and analysis of IoT data. By harnessing these tools, we've demonstrated the process of connecting IoT devices, extracting and processing data, and visualizing it through Power BI dashboards. This integration empowers businesses to make informed decisions based on real-time insights derived from IoT data, enhancing operational efficiency and enabling data-driven strategies. Furthermore it allows us as developers to focus on solving technical challenges on the edge and the shopfloor first without losing the ability to present our project visually to our stakeholders. This supports an agile development process with short cycles while still delivering end-to-end customer value.

Posted on 23.11.2023 08:00, 3320 views