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
- Sign in to Azure portal
- From the search box, type IoT Hub and select IoT Hub under Services
- On the IoT hub page, select + Create
- On the Basics tab of the IoT hub, fill in the with the following details
- 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 the Create button when validation passes to begin creating your new Azure IoT Hub instance
- Wait until the Azure IoT Hub instance is deployed
- Add an IoT device
- When deployment is completed, Click Go to resource from the deployment blade
- To add a new IoT device, scroll down to the Device Management section and select Devices. Then Click + Add device
- 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
- If you do not see the new device, Refresh the IoT devices page.
- Select myRaspberryPi and copy the Primary Connection String value. The key will be needed to authenticate a connection to the Raspberry Pi simulator.
- 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.
- In the code area on the right side, locate the line with 'const connectionString ='
- Replace it with the connection string copied from the Azure portal. Note that the connection sting includes the DeviceId (myRaspberryPi) and SharedAccessKey entries.
- 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.
- Select Stop to stop sending data and return to the Azure portal
- 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
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.