Table of contents
In this blog, we'll explore how to create a practical IoT solution using Azure IoT Hub. Our solution involves setting up an IoT Hub, registering a device, and simulating the device to send telemetry data or files to Azure Blob Storage. Here's a step-by-step guide to get you started.
What is Azure IoT Hub?
Azure IoT Hub is a managed service that acts as a central hub for bi-directional communication between IoT applications and devices. It allows devices to securely send telemetry data to the cloud and receive commands back. This makes it a key component for building scalable, connected solutions for industries like manufacturing, healthcare, and smart cities.
Step 1: Set Up Azure IoT Hub
Azure IoT Hub acts as a central message hub for bi-directional communication between your IoT application and the devices it manages. Follow these steps to set it up:
Log in to the Azure Portal.
Click Create a resource and search for IoT Hub.
Select IoT Hub from the search results and click Create.
Fill in the required details:
Subscription: Choose your subscription.
Resource group: Create a new group or select an existing one.
Region: Select the region closest to your deployment.
IoT Hub Name: Provide a globally unique name for your IoT Hub.
Configure the desired pricing and scale based on your solution's needs.
Click Review + create and then Create to deploy the IoT Hub.
Step 2: Register a Device in IoT Hub
After setting up the IoT Hub, the next step is to register a device that will send data.
Navigate to your IoT Hub in the Azure Portal.
In the left-hand menu, select Devices under Explorers.
Click + Add Device.
Provide a unique Device ID and select the default authentication method (Symmetric key).
Click Save to register the device.
Note down the Primary Connection String for the device, which will be used for device simulation.
Step 3: Simulate a Device to Send Telemetry Data
You can simulate a device to send telemetry data to your IoT Hub using
Raspberri Pi - https://azure-samples.github.io/raspberry-pi-web-simulator/#GetStarted
Open the link above in another browser
Replace
<Your_Device_Connection_String>
with your device connection string nameRun the script:
Message device
Message received
Step 4: Route Data to Azure Blob Storage
To persist device telemetry data, route it to Azure Blob Storage.
Create an Azure Blob Storage account in the Azure Portal.
Navigate to your IoT Hub and select Message routing under Messaging.
Click + Add to create a new route
Name: Provide a route name.
Endpoint: Select Blob Storage and configure your Blob Storage account.
Condition: Leave empty to route all messages.
Click Save to enable the route.
Open storage account
Select Container that was created where the uploaded file will be stored
Select Azure storage
Save Changes
Step 5: Upload Files from a Mobile Device to IoT Hub
To expand your IoT solution, you can also upload files, such as images or logs, from a mobile device to your IoT Hub.
Install an IoT SDK for your mobile platform (e.g., Android or iOS).
Use the SDK to create a client application that connects to the IoT Hub using the device connection string.
Connected
Upload file
Step 6: View Uploaded Files in Azure Blob Storage
Once files are uploaded from the mobile device to the IoT Hub, they will be routed to Azure Blob Storage if you have set up the routing correctly. Here's how to view the uploaded files:
Navigate to your Azure Blob Storage account in the Azure Portal.
Go to the Containers section and select the container where the files are stored.
Browse the list of blobs to locate and download the uploaded file.
Open the file to verify its contents.
Conclusion
You have now successfully set up an IoT solution with Azure IoT Hub! By following these steps, you can simulate devices, send telemetry data, upload files from mobile devices, and store data in Azure Blob Storage for further analysis. This scalable solution is perfect for IoT applications such as remote monitoring, predictive maintenance, and more.
Reference:
https://learn.microsoft.com/en-us/azure/iot/iot-introduction