DEV Community

Cover image for Building a Complete IoT Solution Using Azure: Device Registration, Simulation, and Data Routing
Florence Enenmo
Florence Enenmo

Posted on

Building a Complete IoT Solution Using Azure: Device Registration, Simulation, and Data Routing


The Internet of Things (IoT) is transforming the way we interact with our devices, collect data, make informed decisions, and transform gadgets into smart tools that communicate seamlessly over the Internet. As IoT continues to grow, utilizing its power through practical solutions becomes essential for businesses and developers alike. One such powerful way to leverage IoT is by using an IoT hub to streamline and manage your devices effectively. Imagine being able to register a new device with ease, simulate its activity, and efficiently send telemetry data or files directly to Azure Blob Storage. This seamless integration not only simplifies device management but also ensures real-time data monitoring and storage, empowering you to make informed decisions swiftly. Dive into a step-by-step guide that will help you create a practical IoT solution, and transform your data handling and device management processes today.

Step 1: Set Up Your Azure IoT Hub

  • Sign in to Azure Portal: Navigate to the Azure portal and sign in with your Azure account.

Image description

Create an IoT Hub:

  • Search for IoT Hub and select it.

Image description

  • Click Create.

Image description

Fill in the required details:

  • Subscription: Select your subscription.

  • Resource Group: Create a new resource group or use an existing one.

  • Region: Choose a region close to you.

  • IoT Hub Name: Provide a unique name for your IoT Hub.

  • Click Review + Create

Image description

  • Click Create.

Image description

  • When Your resource is complete, click on Go to resource

Image description

Step 2: Register a Device in Your IoT Hub

  • On the left pane, click on Device Management then also click on Devices

Image description

  • Click on Add Device

Image description

  • Provide a unique Device ID.

  • Optionally, configure other settings like authentication type and primary/secondary keys. The other settings can be left on default for this guide.
    Click Save.

Image description

View of the device created and status enabled

Image description

Get Connection String:

  • After creating the device, to get the connection string, click on the device ID to open its details.

Image description

  • Copy the Primary Connection String. The device will use this to communicate with the IoT Hub.

Image description

Step 3: Simulate a Device to Send Telemetry Data

Image description

Carefully delete text inside the speech mark.

Image description

  • Paste the Primary Connection String earlier copied into the speech mark then run the code.

Image description

  • To send a message from IoT Hub to the device, click on Message to Device.

Image description

  • Type your message in the message body, then click on send message

Image description

  • Message sent successfully

Image description

  • Go back to Raspberry to see the message received

Image description

Step 4: Store Telemetry Data in Azure Blob Storage

  • Create a Storage Account:

  • Go to the Azure portal

  • Search for Storage account and select it.

  • Click Create.

Image description

  • Fill in the required details and create the storage account.

Image description

  • When your resource is complete, click on Go to resource In the left pane, click on Data storage, then Containers Click on +Container

Image description

  • Create a new container for the storage account and click on Create

Image description

Configure Route in IoT Hub:

Navigate to your IoT Hub.

  • In the left pane, click on Hub settings, Message routing and then + Add

Image description

  • On the Add a route select Endpoint

  • Endpoint type: Storage.

  • Endpoint Name: Provide a name for the endpoint.

  • Click on pick a container, then select the storage account and container earlier created.

Image description

  • Select your storage account and container earlier created.

  • Click Select, which takes you back to the Add a route page

Image description

  • For Encoding, select JSON

  • Click on Create + next

Add a route

  • Create a Route

  • Enter a route name

  • Ensure Enable route is checked

  • Set the Data Source to Device Telemetry Messages.

  • On Routing query, leave at default

  • Click on Test

Image description

  • Scroll down and click on Test route If The message matched the query, you can continue to Create + add enrichments

Image description

  • Add any name and value of your choice then click on Add

  • You can create a File upload by clicking on it at the left pane.

  • Click on Select Azure Storage Container

  • Click on the existing storage container or create a new one

  • Click on the existing container and Select

  • It opens a new folder for files

  • Click on Save

We have successfully created an IoT solution using Azure IoT Hub. We set up an IoT Hub, registered a device, simulated the device to send telemetry data, and routed the data to Azure Blob Storage. This setup forms the foundation for a wide range of IoT applications and can be further expanded based on your specific needs.

Top comments (1)

Collapse
 
piya__c204c9e90 profile image
Piya

Very helpful!