DEV Community

Cover image for Guide on How to connect a Raspberry Pi Simulator to a device on IoT Hub
Konkwo Godwin
Konkwo Godwin

Posted on • Edited on

Guide on How to connect a Raspberry Pi Simulator to a device on IoT Hub

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

Step2

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

Image description

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

Image description

Image description

Step 4

Enter a name of your choice for the new IoT device, leave other settings as default and click save.

Image description

Step 5

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

Image description
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

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

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

Image description

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
Completed!

Top comments (0)