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.
Create an IoT Hub:
- Search for IoT Hub and select it.
- Click Create.
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
- Click Create.
- When Your resource is complete, click on Go to resource
Step 2: Register a Device in Your IoT Hub
- On the left pane, click on Device Management then also click on Devices
- Click on Add Device
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.
View of the device created and status enabled
Get Connection String:
- After creating the device, to get the connection string, click on the device ID to open its details.
- Copy the Primary Connection String. The device will use this to communicate with the IoT Hub.
Step 3: Simulate a Device to Send Telemetry Data
After creating the device, and Primary Connection String copied, you can now simulate the device to send Telemetry data to the IoT Hub.
Use a Raspberry Pi Azure IoT Web Simulator to Simulate the Device Telemetry.
[https://azure-samples.github.io/raspberry-pi-web-simulator/#GetStarted]Click on the above link, and locate line 15.
Carefully delete text inside the speech mark.
- Paste the Primary Connection String earlier copied into the speech mark then run the code.
- To send a message from IoT Hub to the device, click on Message to Device.
- Type your message in the message body, then click on send message
- Message sent successfully
- Go back to Raspberry to see the message received
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.
- Fill in the required details and create the storage account.
- When your resource is complete, click on Go to resource In the left pane, click on Data storage, then Containers Click on +Container
- Create a new container for the storage account and click on Create
Configure Route in IoT Hub:
Navigate to your IoT Hub.
- In the left pane, click on Hub settings, Message routing and then + Add
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.
Select your storage account and container earlier created.
Click Select, which takes you back to the Add a route page
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
- Scroll down and click on Test route If The message matched the query, you can continue to Create + add enrichments
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)
Very helpful!