Implement an Azure IoT Hub

In this walkthrough, 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. Sensor data and messages are passed from the Raspberry Pi simulator to your Azure IoT Hub, and you view metrics for the messaging activity in Azure Portal.

Task 1: Create an IoT hub

In this task, we will create an IoT hub.

1. Sign in to the Azure portal.
2. From the All services blade, search for and select IoT Hub and then click + Add.
3. On the Basics tab of the IoT hub blade, fill in the fields with the following details (replace xxxx in the name of the storage account with letters and digits such that the name is globally unique):

4. Move to the Size and scale tab, use the dropdown list to set the Pricing and scale tier to S1: Standard tier.
5. Click the Review + create button.
6. Click the Create button to begin creating your new Azure IoT Hub instance.
7. Wait until the Azure IoT Hub instance is deployed.

Task 2: Add an IoT device

In this task, we will add an IoT device to the IoT hub.

1. When the deployment has completed, click Go to resource from the deployment blade. Alternatively, from the All services blade, search for and select IoT Hub and locate your new IoT Hub instance

2. To add a new IoT device, scroll down to the Explorers section and click IoT Devices. Then, click + New.

  1. Provide a name for your new IoT device, myRaspberryPi, and click the Save button. This will create a new IoT device identity in your Azure IoT Hub.
  2. If you do not see your new device, Refresh the IoT Devices page.
  3. Select myRaspberryPi 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.

Task 3: Test the device using the Raspberry Pi Simulator

In this task, we will test our device using the Raspberry Pi Simulator.

  1. Open a new tab in the web browser and browse to the online Raspberry Pi simulator.
  2. Read about the Raspberry Pi simulator. If there is an overview pop-up select « X » to close the window.
  3. In the code area, right side, locate the line with ‘const connectionString =’. Replace it with the connection string you copied from the Azure portal. Note that the connection sting includes the DeviceId (myRaspberryPi) and SharedAccessKey entries.

4. 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.

  1. Click Stop to stop sending data.
  2. Return to the Azure portal and your IoT Hub.
  3. Switch the IoT Hub Overview blade and scroll down to the IoT Hub Usage information.

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

Note: To avoid additional costs, you can 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. Monitor the Notifications to see how the delete is proceeding.

Leave A Comment

Certifs IT Library

Explore our comprehensive web library to Find a wealth of invaluable resources, including extensive documentation and hands-on labs.

Inscription ouverte pour la formation Vmware VCP-DCV 2024
Mai 2024