How to create IoT Hub and connect it Raspberry Pi Simulator
Tags: programming, azure, learning, beginners
Published: 2023-11-24 15:08:47

## What is IoT?
IoT stands for Internet of Things.
Secure and dependable connectivity between your IoT solution and the devices it controls is made possible by Azure IoT Hub. In order to connect devices, IoT Hub offers a cloud-hosted solution backend with scaled provisioning, device management, and per-device authentication.

## How does it works?
Main Azure PaaS (Platform as a Service) that facilitates bidirectional connectivity between IoT devices and a cloud solution is Azure IoT Hub. Any IoT solution begins with the IoT Hub, which also includes certain crucial features that are shared by all IoT implementations. These include security, networking, computing, and storage capacities.

 

## Creating IoT Hub on Azure portal
1. Sign in to the Azure Portal:
-Open your web browser and go to the Azure Portal.
-Sign in with your Azure account.
2. Navigate to "Create a resource":
- In the left sidebar, click on "Create a resource" or the "+" icon.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ymo4cdco4dvw9k9xyez.png)
3. Search for "IoT Hub":
- In the "Search the Marketplace" box, type "IoT Hub" and press Enter.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7mmc2ybcgazzf27kl47c.png)
4. Select "IoT Hub" from the results:
- In the search results, click on "IoT Hub" from the list of services.
5. Click "Create":
- On the "IoT Hub" page, click the "Create" button to start the creation process.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ahvppazn3hng13had1up.png)
6. Fill the basic information
- select your subscription
- select or create a resource group
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zxjlzfmdoy8dty0394ol.png)
- create the IoT hub name 
- Select region
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3iw8rf7oom8c4t1qclha.png)
7. click Review + create
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/im3uqep1fj6oab1soiyf.png)
8. After validation, click create and wait for it to deploy.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0tf4ilbe3gnuo8lvvqkd.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kfbihyo327xqbwh9qxpp.png)
9. once the deployment is complete, click go to resource
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/en87f79kdhgai35sdcy2.png)
- Select devices
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dnph2l5s5ggu9o8q15p1.png)
- Click add device
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mm14g0s9mvb7b4elun10.png)
- Choose and type a Device ID and leave the rest as default.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y7brjc1jbck6uo9cpxay.png)
- Click save
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bx0ilvflwz1jznzl0y17.png)
- Click on your device under Device ID
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n0n13xcy5eb53z5c4wp2.png)
- Copy primary connection string
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q7rdxst62cdichf7yg5p.png)

## How to connect IoT Hub to Raspberry pi Simulator
- Use this link to go directly to Raspberry Pi Simulator
https://azure-samples.github.io/raspberry-pi-web-simulator/
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wtjk466pbni3k7986p8w.png)
- On line 15, remove what is written between the '' and paste your copied primary connection string.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/309ok3o76oviwf3y970d.png)
Notice that the led light does not blink before connecting, also the message used today and IoT devices in the IoT overview page  before connect must 0 and 0 respectively.
- Click run
- The light on the simulator will start blinking and you will see sending message column
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dto6csryx2h22jalxdoc.png)

- You can also check for the message in IoT overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezct27cvmca9j0six72h.png)