How Azure IoT helped me buy a new house - Part 5 - Azure Stream Analytics

The story so far...

In the first part of this series I described the problem I was having, my hypothesis as to the source of the issue, and the steps I would take to test my hypothesis. In the second post I described the electronics that I built to start capturing environmental sensor data. The third post describes the code for the IoT sensor rig to send telemetry data to Azure IoT Hub. The fourth post addressed the configuration within Azure IoT Hub. This post will get Power BI and Azure Stream Analytics configured to pass data from Azure IoT Hub to Power BI.

Blog Series Table of Contents

Part 1 - Problem Space
Part 2 - Electronics
Part 3 - ESP8266 Code
Part 4 - Azure IoT Hub
Part 5 - Azure Stream Analytics <-- This post
Part 6 - Power BI
Part 7 - Drawing Conclusions

Setup your Power BI instance

We need to have our IoT Hub and Power BI instances setup before we can configure Stream Analytics. Power BI has a 60-day free trial that you can use for this step. If you already have a Power BI instance, skip this step and go right to the Stream Analytics configuration.

Accurate as of 10-May-2018
Navigate to Getting Started with Power BI Desktop and scroll down the page. You will see a section entitled Power BI - Cloud collaboration and sharing which will have a TRY FREE button. Use this to sign up for your free trial.

Setup Stream Analytics

  1. Open the Azure Portal and navigate to your Resource Groups and select the resource group you are using for this project.

  2. In the Resource Group blade, click on the + Add button.

  3. In the Azure Marketplace, search for stream.

  4. In the Results click on Stream Analytics Job

  5. In the Stream Analytics Job blade, click the Create button.

  6. In the New Stream Analytics job blade enter a Job name. This is an arbitrary value. Make sure the Resource group is set to Use existing and then select the Resource Group you have been using for this project. When done, click the Create button.

  7. The New Stream Analytics job blade will close and you should see a Deployment succeeded message box. Now click on the newly created Stream Analytics Job.

  8. In the Stream Analytics Job blade, click on the Inputs menu item.

  9. In the Inputs blade, click on the + Add button and then select IoT Hub from the drop-down list.

  10. In the New Input blade enter an Input Alias. This is an arbitrary name that will be used later in the Stream Analytics Job Query to reference your IoT Hub. Make sure the Select IoT Hub from your subscription radio button is selected so you can pick your IoT Hub below. Select your IoT Hub name. In the Endpoint field select Messaging. In the Shared access policy name field select iothubowner. Our Event serialization format is JSON. Once that is finished, click the Save button.

  11. In the Inputs blade you should now see an Added Input message and your new Input will appear in the list.

  12. Select Outputs from the menu then click the + Add button and select Power BI from the drop-down list.

  13. In the New Output blade, set an Output alias for your Power BI instance. This is an arbitrary name that will be used later in the Stream Analytics Job Query to reference your Power BI instance. In the Dataset name field enter a name for this dataset that will appear in Power BI. In the Table name field enter a name that will be used for the table in Power BI. Both Dataset name and Table name values are arbitrary, so select something that you will recognize when you get to Power BI. Next click on the Authorize button to login to your Power BI instance. By Authorizing here you are allowing Stream Analytics to push data into Power BI on your behalf.

  14. After you successfully Authorize Stream Analytics, the New Output blade will show a Currently authorized as ... message. Click the Save button.

  15. Back in the Outputs blade you should now see an Added Output message box and your Output will appear in the list.

  16. Select Query from the menu. Notice that your new Inputs and Outputs are listed. Since you can have multiple Inputs and Outputs in your Stream Analytics configuration, the Query on the right needs to know which ones you want to use.

  17. In the Query replace the [YourOutputAlias] text with the name of your Power BI Output. Now replace the [YourInputAlias] text with the name of your IoT Hub Input. Click on the Save button to save your changes.

  18. Select Overview from the menu. Note that you can see the Inputs, Outputs and Query for this Stream Analytics Job. The last step is to tell Stream Analytics to start processing data from IoT Hub. Click the Start button.

  19. The Stream Analytics Job will ask you whether you want to start processing data from this point forward (Now), or if you want to start processing existing records as of an earlier date and time (Custom). For our purposes, select Now and click the Start button.

  20. The Status field should change to Starting.

  21. Once the Stream Analytics Job is fully running the Status field will change to Running.

  22. After a few minutes the Overview blade's graphs should begin showing Input Events and Output Events. If these counts are the same then the data is being successfully pulled from IoT Hub and sent to Power BI.

Conclusion (for now)

Now that we have the IoT Sensor rigs sending telemetry data up to Azure IoT Hub, have that data squirreled away for later use, and have the data flowing through Stream Analytics to Power BI we are finally at the point where we can start looking at the data. Remember, our intent is to see how well the a/c is working in the house and whether my presence or absence has any effect.

In the next post we will start playing with data visualizations in Power BI.

Blog Series Table of Contents

Part 1 - Problem Space
Part 2 - Electronics
Part 3 - ESP8266 Code
Part 4 - Azure IoT Hub
Part 5 - Azure Stream Analytics <-- This post
Part 6 - Power BI
Part 7 - Drawing Conclusions