The aim of this walkthrough is to create an IoT hub in Azure portal and configure the hub to authenticate a connection to an IoT device using the Raspberry Pi device simulator.
PREREQUISITE
- Working computer
- Internet connection
- Microsoft Azure account + active subscription
PROCEDURE
LOCATE THE IOT HUB SERVICE
Open the Azure portal and type “IoT” in the search bar at the top. Click on “IoT Hub” under services as seen in the image below.
CREATE AN IOT HUB
On the IoT Hub service webpage that loads, click on the “Create” or “Create IoT hub” button as you deem fit.
You will be directed to the “Basics” page.
The first part of the “Basics” page is the “Project details” section where you are asked to select the subscription and resource group under which you want to create the IoT hub.
PS: In case you want a new resource group, creating a resource group just requires you to provide a name in the input box provided after clicking on “Create new” beneath the “Resource group” input box.
The next section is “Instance details” where you can input an IoT hub name of choice, select a region, tier and daily message limit as required.
Afterwards, click on the “Review + create” button.
A page as shown should appear showing the pricing for the IoT hub specifications selected and the details of the hub.
Click on the “Create” button.
There will be a pop-up at the top right showing the status of the deployment.
You will be directed to an IoT hub deployment page which goes through several phases that you might need to be patient for.
When deployment has been completed, click on “Go to resource”.
The IoT hub resource page loads.
Scroll down to the “Usage” section and take note of “IoT Hub Usage”, which contains messages used and IoT devices—they should have values of 0 at the moment.
ADD IOT DEVICE
On the side menu bar, click on “Device management” and then, “Devices”.
On the Devices webpage that loads, click on “Add Device”.
“Create a device” webpage loads, where a “Device ID” can be inputted. Then, click on the “Save” button.
When that is completed, a notification is sent and the newly created device is listed on the “Devices” webpage.
TEST THE IOT DEVICE
Open the new device and copy the “Primary connection string”—as it will be used to link the device to Raspberry Pi device simulator.
Access the Raspberry Pi device simulator on another webpage using this link: https://azure-samples.github.io/raspberry-pi-web-simulator/
Take note of the unblinking LED which symbolises that a connection to a device has not been established.
In the sample code, locate the line that reads “const connectionString = ‘[Your IoT hub device connection string]’
” (line 15).
Replace the quoted section with the primary connection string that was copied earlier and run the code.
The terminal should have alternating lines of “Sending message” and “Message sent to Azure IoT Hub”.
Also, take note of the blinking diode to depict device connection.
Heading back to “IoT Hub Usage” on the Azure portal should give new details showing the number of connected IoT devices and a message count that should coincide with the “messageID” in the simulator terminal.
That’s all folks!
Top comments (0)