HOW TO CREATE AN AZURE IoT HUB AND CONFIGURE THE HUB TO AUTHENTICATE A CONNECTION TO AN IoT DEVICE USING RASPBERRY PI SIMULATOR
Published: 2023-05-09 19:15:11


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eizrr1c7lxqam0p5dk8f.png)

**The Azure Internet of Things (IoT)** is a collection of Microsoft-managed cloud services, edge components, and SDKs that let you connect, monitor, and control your IoT assets at scale. An IoT solution is made up of IoT devices that communicate with cloud services.

**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. You can connect millions of devices and their backend solutions reliably and securely. Almost any device can be connected to an IoT hub.

**Raspberry Pi Simulator** can serve as the 'Internet Gateway' for IoT devices. When powered by a Cloud network, it acts as a web server for uploading and transiting sensor data on IoT platforms.

Step 1:

Visit portal.azure.com, login or sign up if you don't have an account, you can get a free account at azure.microsoft.com/en-us/free/

Step 2:

Search for IoT Hub and click on create

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2tdoijfxz07ijklvdgkn.png)

Step 3:

1.Subscription: Choose the subscription where you wish to create the resource.
2.Resource group: Choose the resource group where you wish to create the resource. If you wish to create a new group click on create a new option.
3.IoT Hub name: Enter a preferred unique name.
4.Region: Select the location where you wish to create the account.
Click on "Review and Create"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dib34r87fj6zvcakytvo.png)

Step 4:

Click on "create"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/89g3ppkp5ngw4m0uylh6.png)

Step 5:

Your IoT Hub has been created, so click on "Go to Resource"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fy5gxue32s8qs7c5tgzi.png)

Step 6:

To connect an IoT Device, Click on "Devices", then "add device"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sp396azbf0jl8tkji609.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cdcvt4dfz9v3qtho0z0g.png)

Step 7:

Choose a device ID name(I used my name). Every other thing should be left on default, then click on save.
Your IoT Device has been created.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/04unidfmn5a2xcal3mx2.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dyfofzntr4xi739ioted.png)

Step 8:

To Connect your IoT device to a Raspberry Pi Simulator, open a new tab and search for Raspberry Pi Azure IoT Online Simulator. After opening it, you'll notice that there's no blinking on the red stuff and that's because it is switched off but after we work with, it'll be switched on and begin to blink.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yyeyyjhx673vqtn7scbh.png)

Step 9:

Go back to Azure Portal, Click on the IoT Device that was added.
1.Go to 'primary connection string'.
2.Click on it to show then copy to clipbord

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gmyhlubdvgztbm2h6h6.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u7qy6gcwlsyo0z9i4nws.png)

Step 10:

Go back to the Raspberry Pi Simulator, look at line number 15 - remove the place holder _Your IoT hub device connection string_ without touching the apostrophes

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qojum06dgk52o7aimz42.png)

Step 11:

Paste in between the apostrophes, what was copied from the 'primary connection string in step 9.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdlpretr7htkpnaeulgq.png)

Step 12:

Click on run, you'll also notice that the red button is now switched on and blinking and the Raspberry Pi is now sending messages to the IoT device and Hub.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kpfyak18ygnrt80wy14x.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vrqrq4pfzjnqig21k6af.png)

Please note: To be sure that the device has been connected, go back to the azure portal and click on the IoT hub you created, then click on "overview", you'll be able to monitor the IoT hub usage and the number of messages coming in.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jdmzwl8zcd43tfhkyoqo.png)

Thanks for reading...