DEV Community

Cover image for Internet of Things: Creating a Practical Solution using Azure IoT Hub.
Celestina Odili
Celestina Odili

Posted on • Edited on

Internet of Things: Creating a Practical Solution using Azure IoT Hub.

contents
Introduction
Vital Components of IoT
Area of Applications of IoT
Creating a practical IoT solution using Azure IoT Hub

Introduction

The Internet of Things (IoT) refers to the network of physical objects such as devices, vehicles, appliances and lots more embedded with sensors, software, and other technologies that enable them to connect and exchange data with other devices and systems over the internet. IoT represents a significant technological advancement, enabling a more connected and automated world, driving innovation across various sectors.

Vital Components of IoT

  1. Devices/Sensors:

    • These are the physical objects that collect data from their environments. Examples include temperature sensors, smart thermostats, health monitors, and industrial machines.
  2. Connectivity:

    • The collected data needs to be transmitted to a central location for processing. This is done through various communication protocols such as Wi-Fi, Bluetooth, Zigbee, cellular networks, or other specialized IoT protocols.
  3. Data Processing:

    • Once the data is collected and transmitted, it is processed and analyzed. This can happen at the edge (near the data source) or in the cloud, depending on the application.
  4. User Interface:

    • The processed data needs to be accessible to users. This can be through dashboards, mobile apps, or other interfaces that allow users to monitor and control their IoT devices.

Area of Applications of IoT

  1. Smart Home:

    • Devices like smart thermostats, smart lighting, and security systems make homes more efficient and secure.
  2. Wearables:

    • Fitness trackers and smartwatches monitor health metrics like heart rate, sleep patterns, and physical activity.
  3. Industrial IoT (IIoT):

    • Used in manufacturing and supply chain management to monitor equipment health, optimize operations, and increase efficiency.
  4. Smart Cities:

    • Implementing IoT in city infrastructure to improve energy efficiency, reduce traffic congestion, and enhance public services.
  5. Healthcare:

    • Remote patient monitoring, smart medical devices, and telehealth services improve patient care and reduce healthcare costs.

Creating a practical IoT solution using Azure IoT Hub

To achieve this, follow steps below:

back to top

Step 1: Set Up Azure IoT Hub

Create an IoT Hub:

  • Sign in to the Azure Portal. If you do not have one, you can create a free account here.
  • On the search bar, Search and select IoT Hub.

Image description

  • click create

Image description

  • Configure the IoT Hub:
  • Subscription: Select your subscription.
  • Resource group: Create a new resource group or use an existing one.
  • Region: Select a region close to you.
  • IoT Hub Name: Provide a unique name for your IoT Hub.
  • Tier: select free
  • Click Review + create, then Create.

Image description

  • Once the deployment is complete, go to the resource.

back to top

Step 2: Register a Device

  • on the left pane of the IoT Hub created, navigation to device Management
  • select device
  • Click + Add Device.

Image description

  • on the create a device menu, Provide a unique device ID.
  • Click Save.

Image description

Note Down Device Connection String:

  • Select the device you just created.
  • click on the copy icon beside the Primary Connection String, copy it. paste it somewhere, you will need it for your device simulation.

Image description

back to top

Step 3: Configure IoT Hub to Route Data to Blob Storage

Create message routing to Azure Blob Storage

  • Navigate to your IoT Hub.
  • Go to Hub Settings
  • Select Message routing.
  • under route tab, Click + Add

Image description

  • For end point type, Select storage
  • Give the endpoint a name.
  • click Pick a container

Image description

Create a storage account and in turn create a container or select an existing one if you have one created already. For this project, I will be creating a new storage account here.

  • click +Storage account

Image description

  • Provide a name for the storage account.
  • click ok

Image description

  • Once the storage is deployed, click on it to open and add a container.
  • click + container

Image description

  • Provide a name for the container. Ensure to follow the naming convention.
  • click create
  • Click on the container you created.
  • Click select to return to create a route page.

Image description

  • Under encoding, pick JSON
  • click create and next
  • provide a route name. Ensure enable this route is checked.
  • For data source, Choose Device telemetry message.
  • Click test, test route. Ensure you see "the message match the query" and then continue.
  • click create +skip enrichments or create +add enrichments. Here, we will create +add enrichments.

Image description

  • Add a name and value if you choose create + add enrichments
  • Click add
  • Ensure you can see the created route back to top

Create File Upload

  • Navigate to your IoT Hub.
  • Select Hub setting.
  • Click File upload.
  • Click select Azure storage container

Image description

  • Select container and storage account you created.
  • save

Image description

  1. Upload Image to IoT plug and play:
  • Go to your smartphone app store, download and install IOT plug and play app and then open the app.
  • click on scan QR code then click connect manually,

Image description

  • paste the primary connection string copied earlier on the Iot hub device connection string path.
  • click connect.

Image description

  • choose upload image.
  • Upload any image of your choice

Image description

back to top

Step 4: Verify Data in Blob Storage

Once your connection to the IoT plug and play is successful, a folder with the telemetry data will be created for you. Another folder with the uploaded file will be created too after file upload is created.

  • Go to Your created storage container in Azure, click the folders to view the image uploaded.

Image description

  • To view telemetry data,
  • click the folder containing the name of your IoT. Here it is amazing-world-iot. Open it until you see a file with .json extension.
  • click on the three dot on right of the file to download the .json file or generate SAS link
  • Open it on visual studio code. The telemetry data should look like this when opened.

Image description

back to top

Step 5: Simulate a Device to Send Telemetry Data (Practical IoT Solution)

*Communication from device to cloud *

  • On the IoT hub, go to device
  • Select your device to open it
  • click on device twin and notice editable in line 37

Image description

Image description

  • go to IoT plug and play app
  • click on property and go to editable
  • edit it with any message and send

Image description

  • go back to device twin and notice the message sent appeared in line 37.

Image description

Using Direct Method

  • On the IoT hub, go to device
  • Select your device to open it
  • Click on direct method

Image description

  • Provide a method name for example lightOn
  • Under payload, write a JSON command. for this guided we will use existing command, copy and paste any of the commands below
    for light on,
    {
    "duration ": 3,
    "deley": null
    "pulse": 2
    }

  • Click invoke method

Image description

back to top

Top comments (0)