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. This post will address the configuration within Azure IoT Hub.

Blog Series Table of Contents

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

Azure IoT Hub Configuration recap

In Part 3 of this series we Setup an Azure IoT Hub instance and added entries for our ESP8266-based sensor rigs.

Storing the telemetry

I wanted to keep the messages generated by my sensors so that I can review them or perform other activities on the dataset. To enable this I needed to tell the Azure IoT Hub to squirrel the message payloads away. For that to work I created an Azure Storage Account and configured Azure IoT Hub to store incoming messages there.

NOTE: If you are following along with the series and have no desire to use this data for anything other than the Power BI dashboard, then you can safely skip the steps in this post and move on to Part 5 - Stream Analytics.

Setup a Storage Account

We are going to store the messages in blob storage so we need to setup a Storage Account. Use the steps in Create a storage account with the following settings per step.

  1. Login to Azure with the credentials you used to create the IoT Hub.
  2. n/a
  3. Follow the naming rules listed in the article.
  4. Use the Resource Manager (default) deployment model. The Classic is so 2015.
  5. Select General purpose storage account type.
  6. For my purposes, I used LRS (Locally-redundant storage) for this project. If this data is more important than mine, I'd advise going with a GRS replication option.
  7. Use the same subscription that you used when creating the IoT Hub.
  8. I used the same Resource Group that holds my IoT Hub so that everything is easy to find.
  9. I place the Storage Account in the same Region as my IoT Hub so that there is less latency.
  10. Yeah...do this.

Add the endpoint to your IoT Hub

  1. Open the Azure Portal and navigate to your IoT Hub.

  2. Scroll down to the Messaging section and click on Endpoints
    IoTHub-endpoints

  3. In the Endpoints page click on the + Add button to create a new endpoint.
    IoTHub-endpoints-add

  4. In the Add endpoint blade enter a name for the endpoint and select Azure Storage Container for the Endpoint type. This will show an extended set of inputs. Click on the Pick a container arrow.
    IoTHub-endpoints-add-pick-container

  5. In the Storage Accounts list, select the storage account you created earlier. This will show the Storage account > Containers blade.
    IoTHub-endpoints-add-pick-container-pick-sa

  6. In the Containers blade click on the + Container button.
    IoTHub-endpoints-add-pick-container-pick-sa-add-container

  7. In the New container dialog enter the name of your storage account container. Leave its Public access level set to Private. Click the Ok button to save the container.
    IoTHub-endpoints-add-pick-container-pick-sa-add-container-config

  8. Back in the Containers blade, select the new container and click the Select button.
    IoTHub-endpoints-add-pick-container-pick-sa-select-container

  9. Back in the Add endpoint blade, note that the Azure Storage Container field is now filled. Click on the OK button to add the endpoint to your IoT Hub.
    IoTHub-endpoints-add-ok

  10. Back in your IoT Hub's Endpoints blade, you should now see the newly created endpoint.
    IoTHub-endpoints-created

Route the messages into the storage account endpoint

We are going to create a routing rule that sends all of the sensor messages to our storage account.

  1. Open the Azure Portal and navigate to your IoT Hub.

  2. Scroll down to the Messaging section and click on Routes
    IoTHub-routes

  3. In the Routes blade click the + Add button.
    IoTHub-routes-add

  4. In the Create new route blade, enter a name for your rule, select Device Messages in the Data Source field, select the storage account endpoint we just created in the Endpoint field, and make sure Enable Rule is set to On. Click the Save button to save your changes.
    IoTHub-routes-add-create

  5. Back in the Routes blade you should now see your new Route directed at your new Endpoint.
    IoTHub-routes-add-created

Determine if the Route is working

One of the easiest ways to determine if your route is working is to use Azure Storage Explorer to look at the contents of the Storage Account behind your endpoint. After connecting Storage Explorer to your Azure account, navigate to the storage account you used earlier. You should see a storage container named for your IoT Hub instance.
Storage Explorer showing blob root

If you drill down into the storage container you will eventually get to a blob with your data.
Storage Explorer's endpoint blob

Opening that blob shows the message that your sensor rigs sent to Azure IoT Hub during the minute shown in the blob's path.
Storage Explorer's endpoint blob contents

Conclusion (for now)

Now that we have the IoT Sensor rigs sending telemetry data up to Azure IoT Hub, and have that data squirreled away for later use, we can proceed toward getting the data to show up in Power BI. To do that we need to use Azure Stream Analytics as our conduit.

In the next post we will setup a basic Power BI environment and configure Stream Analytics to push data into it.

Blog Series Table of Contents

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