Guide on How to connect a Raspberry Pi Simulator to a device on IoT Hub
Published: 2023-05-03 02:18:14

## Internet of Things
Internet of Things( IoT) is a network of devices connected to the internet that are able to exchange real time data with other connected devices and systems over the internet or other networks. Azure IoT Hub is a managed service hosted in the Cloud that acts as a central messaging hub for communication between an IoT application and it's connected devices. In this article, Azure IoT Hub will be created in Azure Portal and connected to IoT device then authenticated with a Raspberry Pi Simulator. 


## Create an IoT Hub

## Step1
Login to Azure Portal search for IoT Hub then select IoT hub under services. On the IoT Hub page select create. On the basics tab create new resource group, enter an IoT hub name, select region leave Tier and Daily message count as default

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

## Step2

Click Review + Create to validate input data then click create to deploy the IoT Hub

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

## Add an IoT  device

## Step 3
After IoT hub deployment, click on **Go to  resource**
, under  Device Management section click devices, then click Add device. 

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


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

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


## Step 4
Enter a name of your choice for the new IoT device, leave other settings as default and click save.
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gzl6h6sm5fz74g65jkvo.png)

## Step 5
If you don't see the new device click refresh on the IoT device page

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eax8f8rahccxyo130ugd.png)
Step 6
Click the IoT device you just created and copy the the primary connection string value which is used to authenticate a connection to the Raspberry Pi Simulator. 

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

### Testing the device using a Raspberry pi simulator

Step 7
 Visit azure-sampled. github. IoT/ raspberry-pi-simulator/#Getstarted to use Raspberry pi simulator device. 

Step 8
In the code area locate the line with " const connection String ="

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


Step 9
Replace ( the IoT hub device connection string) with the connection string copied from Azure Portal

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


Step 10
Click run on the Raspberry application, the console output should show the sensor data and messages that are sent from the Raspberry Pi Simulator to the Azure IoT Hub. Note that data and messages are sent each time the Raspberry pi LED flashes

Step 11
To check the number of messages from Raspberry Pi simulator go to Azure Portal click overview on the Azure IoT hub page and scroll down, under IoT Hub Usage you will see the number of messages. 


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