DEV Community

Tolu Iyoriobhe
Tolu Iyoriobhe

Posted on

Implementing an 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.

Here, we will be configuring an Azure IoT Hub in Azure portal and authenticating a connection to an IoT device using online Raspberry Pi device simulator. If you have time, you can read more about the Raspberry Pi simulator.

- Creating an IoT Hub

  1. Sign in to Azure portal
  2. From the search box, type IoT Hub and select IoT Hub under Services IoTHub
  3. On the IoT hub page, select + Create IoT Hub create
  4. On the Basics tab of the IoT hub, fill in the with the following details Iothub basics tab field Iothub basics tab
  5. Go to the Management tab and use the dropdown to set the Pricing and scale tier to S1:Standard tier
  6. Click the Review + Create button and select the Create button when validation passes to begin creating your new Azure IoT Hub instance Create IoT Hub
  7. Wait until the Azure IoT Hub instance is deployed

- Add an IoT device

  1. When deployment is completed, Click Go to resource from the deployment blade Iot hub deployment blade
  2. To add a new IoT device, scroll down to the Device Management section and select Devices. Then Click + Add device Add IoT device
  3. Provide a name for your new IoT device, myRaspberryPi, and click Save. This will create a new IoT device identity in your Azure IoT Hub Device ID
  4. If you do not see the new device, Refresh the IoT devices page.
  5. Select myRaspberryPi and copy the Primary Connection String value. The key will be needed to authenticate a connection to the Raspberry Pi simulator. IPrimary connection string

- Testing the device using a Raspberry Pi Sumulator

Open a new tab in the web browser and type or copy this shortcut link https://aka.ms/RaspPi. It will take you to a Raspberry Pi Simulator site. When done select 'X' to close the pop-up window.

  1. In the code area on the right side, locate the line with 'const connectionString =' const connectionString
  2. Replace it with the connection string copied from the Azure portal. Note that the connection sting includes the DeviceId (myRaspberryPi) and SharedAccessKey entries. Run sample code
  3. Click Run to run the application. The console output should show the sensor data and messages that are sent from the Raspberry Pi simulator to the Azure IoT Hub. Data and messages are sent each time the Raspberry Pi simulator LED flashes. Console data
  4. Select Stop to stop sending data and return to the Azure portal
  5. Switch to the IoT Hub Overview blade 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 IoT Hub Usage

Awesome! We just set up Azure IoT Hub to collect sensor data from an IoT device.

Note: To avoid additional costs, you can optionally remove the resource group. Search for resource groups in the search box, select your resource group and click Delete resource group.


Top comments (1)

Collapse
 
lawrencia profile image
Princesse Lawrie

This is so detailed and helpful, thanks