DEV Community

Peter Edozie
Peter Edozie

Posted on

Implementation of Azure IoT Hub

The Internet of Things (IoT) is a network of physical devices that connect to and exchange data with other devices and services over the Internet or other network.
Azure IoT Hub is a managed service hosted in the cloud that acts as a central message hub for communication between an IoT application and its attached devices. You can connect millions of devices and their backend solutions reliably and securely.

With these few steps, we will configure a new Azure IoT Hub in Azure Portal, and then authenticate a connection to an IoT device using the online Raspberry Pi device simulator.

First Step: create an IOT Hub

  • Sign in to Azure portal

  • Search for and Select IOT HUB

  • On the Iot Hub page click + Create

  • On the Basics tab of the IoT hub page, fill in the fields with the following details
    Image description

  • Go to the Management tab, and use the dropdown to set the Pricing and scale tier to S1: Standard tier.

  • Click the Review + create button and Select Create to begin creating your new Azure IoT Hub instance.

  • Wait until the Azure IoT Hub instance is deployed.

Second step: Add an IoT device

  • When the Deployment is done, click Go to resources.
    Image description

  • To add a new IoT device, scroll down to the Device management section and click Devices. Then, click + Add Device.
    Image description

  • Provide a name for your new IoT device, Azdevice, and click the Save button. This will create a new IoT device identity in your Azure IoT Hub.
    Image description

  • If you do not see your new device, Refresh the IoT Devices page.

  • Select Azdevice and copy the Primary Connection String value. You will use this key in the next task to authenticate a connection to the Raspberry Pi simulator.
    Image description
    Image description

Last Step: Test the device using a Raspberry Pi Simulator

we will test our device using the Raspberry Pi Simulator.

  • Open a new tab in the web browser and type this shortcut link (https://aka.ms/RaspPi.) It will take you to a Raspberry Pi Simulator site. If you have time, read about the Raspberry Pi simulator. When done select “X” to close the pop-up window

  • In the code area on the right side, locate the line with ‘const connectionString =’.
    Image description

  • Replace it with the connection string you copied from the Azure portal. Note that the connection sting includes the DeviceId (Azdevice) and SharedAccessKey entries.

    Image description

  • Click Run (below the code area) to run the application. The console output should show the sensor data and messages that are sent from the Raspberry Pi simulator to your Azure IoT Hub. Data and messages are sent each time the Raspberry Pi simulator LED flashes.
    Image description

  • Click Stop to stop sending data.

  • Return to the Azure portal.

  • Switch the IoT Hub Overview page and scroll down to the IoT Hub Usage information to view usage. Change your timeframe in the show data for last to see data in the last hour.
    Image description

Congratulations! You have set up Azure IoT Hub to collect sensor data from an IoT device.

Note: To avoid additional costs, you can optionally remove this resource group. Search for resource groups, click your resource group, and then click Delete resource group. Verify the name of the resource group and then click Delete.

Thank you.

Discussion (0)