Saving IoT Hub messages to Azure Blob Storage

Introduction

Microsoft Azure provides a cloud service that provides storage that is highly available, secure, durable, scalable, and redundant, under the name of Microsoft Azure Storage.

There is no limit on storage capacity and your account is charged depending on the amount of data stored by you.

Microsoft Azure Storage provides five types of storages:

  • Blob storage
  • Files storage
  • Queues storage
  • Tables storage
  • Disks storage

 

Azure blob storage is a service for storing large amounts of non-structured object data that can be accessed from anywhere in the world using http or https. Blob storage can be used to present data publicly or to store data privately.

 

For more information on the types of Azure storage, refer this Azure documentation on storage.

 

For storing IoT Hub messages on to Azure Blob Storage, we will require an IoT Hub and an application that sends data to this IoT Hub.

If you do not already have a Microsoft Azure account, you can refer the topic Microsoft Azure Free Sign-Up in the Getting Started section of Microsoft Azure to create a free account.

If you have not created an IoT Hub already, you can refer the topic Creating an IoT Hub in Microsoft Azure in the Getting Started section of Microsoft Azure.

If you do not have an application that sends data to your IoT Hub, you can refer the topic Sending DHT11 sensor data to IoT Hub using NodeMCU in the Getting Started section of Microsoft Azure.

 

Creating an Azure Storage Account

Follow the steps given below to create your Azure Storage Account :

1.  Sign in to your Microsoft Azure account.

2.  Select New --> Storage --> Storage account

New Storage Account

3.  After you click on Storage account, a Create Storage Account pane (window) will open. Fill in the basic information asked in this pane.

  • Name : Select a name for your storage. The name should be globally unique. If the name is valid, a green check mark will appear.
  • Deployment Model :Select Resource Manager.
  • Account Kind : Select General Purpose.
  • Performance : Select Standard.
  • Replication : Select Zone-Redundant Storage(ZRS).
  • Secure Transfer Required : Select Disabled.
  • Resource Group : Select Use Existing option and use the same resource you used to create your IoT Hub.
    You need to scroll down to see this option in the pane.
  • Location : Select the location closest to you.
    We have selected Central India.
  • You can choose to pin this Azure Storage to the dashboard by checking the Pin to dashboard option.
  • Click on Create to create the Storage Account. It may take a few minutes to create the Storage Account.
    You will get a notification on completion of creation of the Storage Account.

Storage Account Details

 

Now that we have created a Microsoft Storage Account, we need to add the Storage Account as an endpoint to the IoT Hub.

The IoT Hub supports routing messages to a Storage Account.

 

Storage Account as Endpoint to IoT Hub

1.  Go to your IoT Hub and click on Endpoints under Messaging.

2.  Click on Add to add an Endpoint.

Add Endpoint

3.  An Add Endpoint pane will open. Enter a name for the endpoint and select the type of endpoint as Azure Storage Container. More options will appear after selecting the type of endpoint as Storage Container.
Using the picker select the Storage Container you created. Do not modify the other options.
After selecting your Storage Container, create a Container and select it.

Endpoint Details

 

Endpoint Details 2

 

Endpoint Details 3

 

Endpoint Details 4

4.  Click OK.

 

Now that we have added Storage Account as an endpoint to route message received by IoT Hub to the Storage Account, we need to define a route for this.

 

Adding Route for Routing Data

1.  Go to your IoT Hub and click on Routes under Messaging.

2.  Click on Add to add a Route.

Add Route

3.  A new pan named Create a new route will open. Enter a name for the route.
Select Device Messages as the Data Source.
Select the endpoint that was just created as the Endpoint.
Select Enable Rule as On.
Enter true as the Query String.

Route Details

4.  Click on Save.

 

Adding a Route for Hot Path Telemetry (Optional)

This is required if additional processing is done on the telemetry messages.

Follow the same steps as given for Adding Route for Routing Data. The only difference is, in step 3, while selecting the Endpoint, select events as the endpoint. events is the default built-in endpoint.

Hot Path Route

Now that we have set the route for routing the IoT Hub messages to the Storage Account, we can connect the application that sends data to the IoT Hub and check the Storage Account for the messages.

 

Connect the application and start sending data to your IoT Hub.

Open your Storage Container from the Storage Account on Microsoft Azure. (Storage Account will be accessible from the dashboard if you have pinned it to the dashboard)

You will see a folder with the name of your IoT Hub.

You will find files inside the folder and can download it from there.

Storage Account


Ad