DEV Community

Cover image for CREATING AN IOT HUB IN AZURE PORTAL
Emmanuel Oluajo
Emmanuel Oluajo

Posted on

CREATING AN IOT HUB IN AZURE PORTAL

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.

Image description

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.

Image description

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.

Image description

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.

Image description

There will be a pop-up at the top right showing the status of the deployment.

Image description

Image description

Image description

You will be directed to an IoT hub deployment page which goes through several phases that you might need to be patient for.

Image description

Image description

When deployment has been completed, click on “Go to resource”.

Image description

The IoT hub resource page loads.

Image description

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.

Image description

ADD IOT DEVICE

On the side menu bar, click on “Device management” and then, “Devices”.

Image description

On the Devices webpage that loads, click on “Add Device”.

Image description

“Create a device” webpage loads, where a “Device ID” can be inputted. Then, click on the “Save” button.

Image description

When that is completed, a notification is sent and the newly created device is listed on the “Devices” webpage.

Image description

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.

Image description

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.

Image description

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.

Image description

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.

Image description

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.

Image description

That’s all folks!

Top comments (0)