Connecting Raspberry Pi Simulator to Azure IoT Hub
Tags: cloud, cloudcomputing, azure, iothub
Published: 2023-04-05 12:15:05

## What is Azure IoT Hub
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 services hosted in the cloud that acts as a central message hub for communication between an IoT application and its attached devices.

In this guide 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**, to read more about Raspberry Pi device simulator visit [www.techrepublic.com/article/raspberry-pi-simulator-lets-you-start-tinkering-without-even-owning-a-pi/](url)

**Create an IoT Hub**

**Step 1:**
Visit [portal.azure.com](url), login or sign up if you don't have an account, you can get a free account at [azure.microsoft.com/en-us/free/](url)

**Step 2:**
From the search box, enter IoT Hub and select IoT Hub under services.

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

**Step 3:**
On the IoT Hub page **select Create**

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

**Step 4:**
On the basic tab of the IoT Hub, follow the following steps.

Resource Group
Create a new resource group by clicking create new option shown below the input bar, you can use any name of your choice.

IoT Hub Name
Enter any name of your choice

Region
Select a region where the IoT Hub will be located, in this example i will be using **East US**

Tier
Leave as default

Daily Message Count
Leave as default

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

**Step 5:**
Click **Review+Create** button as seen in the image below

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

**Step 6:**
**Click Create** button when validation passes to begin creating your new Azure IoT Hub instance.

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

**Step 7:**
When deployment is completed, **click Go to resource**

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

**Add an IoT Device**

**Step 1:**
To add a new IoT Device, under Device Management section **click devices**. Then **click Add device**

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

**Step 2:**
Enter any name of your choice for your new IoT device, in this example i will be using **MyIoTDevice**, leave every other settings as default and **click save**

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

**Step 3:**
If you do not see the new device **click Refresh** on the IoT device page.

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

**Step 4:**
Click the IoT device you just created and **copy the primary connection string value**
The string will be needed to authenticate a connection to the Raspberry Pi Simulator.

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

**Testing the device using a Raspberry Pi Simulator**

**Step 1:**
Visit [azure-samples.github.io/raspberry-pi-web-simulator/#GetStarted](url) to use Raspberry Pi Simulator Device.

**Step 2:**
In the code area on the top right corner, **locate the line with "const connectionString="**

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

**Step 3:**
**Replace [Your IoT hub device connection string]** with the connection string copied from Azure portal.

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

**Step 4:**
**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.

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

**Step 5:**
Go back to Azure portal, **click Overview** on the Azure IoT hub page and **scroll down**, then under **IoT Hub Usage** you will see the numbers of messages sent from the Raspberry Pi Simulator.

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

**Voila! that is all.**