How to Build a Real-Time IoT Dashboard with Azure IoT Hub, Azure Stream Analytics and Power BI

Azure provides a set of services that allow you to visualize IoT device data in real-time. The data pipeline is: IoT Device –> Azure IoT Hub –> Azure Stream Analytics –> Power BI. Follow along with this post if you want to build out a simple version to get your started. Please leave a comment if you have any issues along the way.

Here’s the end result…trust me, it updates in real-time once you build this out.

Azure IoT Hub

Follow my “how to Get Started with Azure IoT Hub and a UWP App” to get the IoT Hub setup and the code that will run on your emulated IoT device. When you setup the IoT Hub, choose the S1 option instead of free if you want to write more than 8k messages a day.

After following that post you should have UWP IoT Device <–> Azure IoTHub working.

Now, let’s modify the device code to write more than a simple string to the IoT Hub.

IoT Device Code

This is the code that will run on the emulated IoT Device. It will write random JSON Serialized messages to your IoT Hub. The data model is simple a single “Participant” class with “Position” and “Count” properties.

public class Participant
     public int Position &#123; get; set; &#125;
     public int Count &#123; get; set; &#125;

1. Clone this repo:

2. Open the DeviceKey.txt file and paste in your device connection string from the Azure Portal. (I don’t do much UWP dev and couldn’t quickly figure out how they want us to store config settings like this, so I just dropped it in a text file. LMK if you know a better way to manage config settings)

3. Compile and move onto next step.

Azure Stream Analytics

Stream Analytics will take messages from IoT Hub and push them to Power BI. There are three things you need to configure: input, query and output.

1. Go to the old Azure Portal:

2. Create a new Stream Analytics

3. Connect the “input” to the IoT Hub you created earlier. Choose “Data stream”, “IoT Hub”, “JSON” and “UTF8”

4. Connect the “output” to Power BI. You will need to authenticate to Power BI.

5. Write a query that connects your IoT Hub input to your Power BI output.

6. Click the Save button.

7. Start the Stream Analytics job.

Power BI

Stream Analytics will automatically create the Power BI dataset after you send the first message to it.

1. Open up the UWPIoTDevice project you cloned earlier and send a single message.

2. Go to You should see that the Power BI dataset has been automatically created.

3. Click on the dataset, add the position and count fields.

You should now see something like this:

4. Go back to the UWP app and send some more messages, then come back to Power BI and click Refresh. You should now see something like this:

Modify the appearance however you’d like. I just added data labels to mine

5. Click “Save” in the upper right hand corner and give the report a name:

VERY IMPORTANT: Save the report before pinning the visual to the dashboard.

6. Click on the “Pin” icon on that visual and pin it to a dashboard.

7. Open your dashboard

8. Open the UWPIoTDevice app and send some more messages

You should now see the dashboard being updated in real-time as you send more messages to it.