DEV Community

Cover image for Practical IoT solution using Azure IoT Hub.
Olaolu' Afolami
Olaolu' Afolami

Posted on

Practical IoT solution using Azure IoT Hub.

Microsoft Azure offers Azure IoT Hub, a robust managed service that serves as a single hub for managing and connecting Internet of Things (IoT) devices. Let us examine the specifics:

Objective and Usability:
Central Hub: The foundation of all IoT applications developed on the Azure platform is Azure IoT Hub. It makes it easier for cloud services and Internet of Things devices to communicate seamlessly.
Secure and consistent connectivity is guaranteed between your IoT application and the devices it is linked to.

  • Scalability: An IoT Hub instance may be linked to millions of devices.

  • Device Management: The IoT Hub has tools for managing, authenticating, and provisioning devices.

Important characteristics:

  • Device-to-Cloud Telemetry: Gather information from gadgets to comprehend their condition and actions.

  • Cloud-to-Device Messages: Notifications and orders can be sent to linked devices from the cloud.

  • Security and Authentication: To improve security, authenticate every device separately.

  • Automate the registration and provisioning of devices.

  • Over-the-Air Updates: Update firmware and software on devices to keep them current.

  • Integration with Azure Services: You can effortlessly include Event Grid, Azure Functions, and other Azure services with ease.

  • IoT Edge Integration: Use Azure IoT Edge to expand your solution from the cloud to the edge.

Use Cases:

  • Smart Cities: Keep an eye on and control traffic signals, trash cans, lamps, etc.

  • Industrial IoT: Monitor the condition of machinery, enhance productivity, and raise security.

  • Healthcare: Keep an eye on hospital facilities, medical equipment, and patient vitals.

  • Agriculture: Gather information with sensors in cattle, greenhouses, and fields.

  • Retail: Track assets, keep an eye on inventories, and improve customer service.

Practical steps using a mobile device (Samsung phone).

  • Set Up Azure IoT Hub.

  • Register a Simulated Device (Samsung phone).

  • Simulate the Device

  • Azure Blob Storage Integration.

Step 1: Set Up Azure IoT Hub

  • Log in to your Azure account.

  • Search for “IoT Hub” and click “+ Add.”

  • Configure the settings below:

Name: Choose a unique name for your IoT Hub.

Pricing Tier: Select the appropriate tier based on your requirements.

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

Region: Choose a region close to your devices.

  • Click on Review + Create

IoT Hub

IoT Hub
Resource

Step 2: Register a Simulated Device.

Create a Simulated Device:

  • From your IoT Hub overview page:

Click Device from the Device management blade.

  • Select + Add device.

Device Add

  • Provide the Device ID

  • Choose an authentication type (e.g., symmetric key).

  • Leave the default values of the other fields and select Save.

Device

  • Go to the Device Overview page and click the newly created device (Samsungphone).

Device

  • On your device (The smart phone in this case the Samsung phone), go to _Playstore _ and download the app called IoT PnP

  • On the landing page, click on Scan QR code as indicated below.

QR code

  • Click on Manually connect.

connect

  • Select the IoT Hub device connection string radio button.

Connection string

  • Paste the Primary Connection String in the IoT Hub device connection string field and click the Connect button.

Connect string

  • The telemetry data of the phone is displayed.

Telemetry details

Azure Blob Storage Integration

  • Navigate to the IoT device overview page and select Message routing from the Hub settings blade.

Message Route

Select + Add to add a route.

+ Add

  • Select Storage as the Endpoint type, provide the Endpoint name and select the Jason as the encoding type.

  • Click on the Pick a container button to begin creating a storage account.

Endpoint

  • Click the + Storage account option to create a storage account.

Storage

  • Provide the Storage details as indicated in the screenshot below and click the Ok button:

Storage

  • Select the created storage account (phonestorage).

Storage

  • Create a Container. Container

storage

  • Click on Create to provision the container (phonefiles) .

Container

  • Select the container created.

Container

  • Click the Create + next button to proceed.

Proceed

  • Enter a route name and select a Device Telemetry message in the Data source drop-down and click Test to test the route.

Route

  • Click the _Create + add enrichment button.

enrichment

  • Click the Add button.

rtt

  • Navigate to the created IoT hub212 and select File upload from the Hub settings blade.

fileupload

  • Select Azure storage container.

Storage container

  • Select the created container (phonefiles).

Container

  • Turn on file notification settings then click save.

Image

  • From your mobile phone, click on Image upload.

Image upload

Image upload

  • Upload an image from your phone.

Image upload

  • Navigate to your Blob Storage to view the uploaded file.

storage folder

The uploaded files.

Files

Viewing the telemetry data using Visual studio code.

Navigate to the storage folder and download the Json files and view them in Visual studio code editor.

Json files

Image description

  • For Bi-directional data, from your mobile phone, click on the Properties tab from the IoT plug n Play app.

properties

  • Click on the Editable property tile, edit it with any word or sentence and click on Send.

image

  • Navigate to the IoT hub and select the created device (Samsungphone) .

device

  • Click on device twin.

  • The edited string now appears in line 37 of the Json code.

edited

This simulation demonstrated the seamless integration between our device and Azure IoT Hub. Here are the key takeaways:

Data Persistence in Azure Blob Storage:

  • Our device successfully saved telemetry data to Azure Blob Storage.

  • This demonstrates the reliability and scalability of our chosen solution.

Telemetry Monitoring:

  • We monitored the telemetry data from our mobile device, gaining valuable insights, and archived logs for auditing and troubleshooting.

  • Real-time monitoring allows us to make informed decisions promptly.

Exploring Further Use Cases:

  • Beyond this simulation, there are numerous other scenarios we can explore:
    Image Storage: Store images captured by our devices.

  • Streaming Data: Process real-time streams from sensors.

  • Data Archiving: Long-term storage for compliance or historical analysis.

Kindly comment, like and share.

Top comments (0)