How to send messages to IoT Hub in Azure
Published: 2023-03-27 15:29:12

The Internet of Things (IoT) describes the ability of devices equipped with sensors to collect data and send that data to an endpoint for logging, processing, analysis, and/or other actions.
Consolidating sensor data is just one aspect of IoT. Controlling and managing the distributed devices is another aspect. 
The scenarios below are examples of IoT
 Consider an automobile manufacturer that builds sensors into its vehicles to monitor performance and sends that data to Azure for real-time analytics Or
 Imagine a connected house where the refrigerator, oven, microwave, lighting systems, garage door, thermostat, and security system all collect and send data to a central app or service to enable the homeowner to monitor and potentially control the function of all of these systems Or
 Consider a manufacturing floor where sensors track the manufacturing process and send data back to a centralized system that operators and engineers use to monitor and control the manufacturing process.

Azure includes several services that enable organizations to integrate IoT devices quickly and easily and deploy solutions based on IoT.

Azure IoT has 3 components 

 Azure IoT Hub Azure IoT Hub: is an Azure-hosted service that functions as a message hub for bi-directional communication between your deployed IoT devices and Azure services.
• IoT Hub supports multiple protocols and open-source software development kits (SDKs), enabling it to integrate most IoT devices.
• IoT Hub is highly scalable, which means it can integrate billions of devices.
• IoT Hub supports multiple communication and control functions.
• IoT Hub can route messages received from devices to other Azure services as needed.
• IoT Hub is the service that integrates your IoT devices and other Azure services. However, IoT Hub does not provide analysis services or dashboards for viewing device state or analyzing data. That is where IoT Central comes in.
Below describes the procedure on how to send messages to IoT Hub in Azure
 Go to Azure portal
 On the search bar, type IoT Hub and search
 Click on create

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

 Input all necessary details as indicated in the image below and click on review and create

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

 After the IoT Hub has finished deployed

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

 Create on Resources and then you have your IoT Hub

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

Step 2 is adding an IoT device
Click on devices after which a page will displace and click add device

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

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

Put name on device ID and click on save then you have the below image, at this stage you have successfully add an IoT device

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

Step 3 is testing the device using the Raspberry Pi Simulator.
Click on the name you used as your device ID, then you have your ID details as shown in the image below

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

Next is to click and copy the primary connection String and paste it on your downloaded Raspberry Pi simulator on number 15 that is, replace what you have in the raspberry pi with the Primary connection string you copied then click on run

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

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

Next is to go back to your Azure portal and check for messages sent to your IoT Hub

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

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

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

From the above image you can see messages has been sent to the IoT Hub.