Connect a Raspberry Pi to your Azure IoT Central application (Python)
This article describes how, as a device developer, to connect a Raspberry Pi to your Microsoft Azure IoT Central application using the Python programming language.
Before you begin
To complete the steps in this article, you need the following:
- An Azure IoT Central application created from the Sample Devkits application template. For more information, see Create your Azure IoT Central Application.
- A Raspberry Pi device running the Raspbian operating system. You need a monitor, keyboard, and mouse connected to your Raspberry Pi to access the GUI environment. The Raspberry Pi must be able to connect to the internet.
- Optionally, a Sense Hat add-on board for the Raspberry Pi. This board collects telemetry data from various sensors to send to your Azure IoT Central application. If you don't have a Sense Hat board, you can use an emulator instead.
An application created from the Sample Devkits application template includes a Raspberry Pi device template with the following characteristics:
|Field name||Units||Minimum||Maximum||Decimal places|
|Display name||Field name||Units||Decimal places||Minimum||Maximum||Initial|
|Display name||Field name||On text||Off text||Initial|
|Type||Display name||Field name||Data type|
|Device property||Die number||dieNumber||number|
Add a real device
In your Azure IoT Central application, add a real device from the Raspberry Pi device template and make a note of the device connection string. For more information, see Add a real device to your Azure IoT Central application.
Configure the Raspberry Pi
The following steps describe how to download and configure the sample Python application from GitHub. This sample application:
- Sends telemetry and property values to Azure IoT Central.
- Responds to setting changes made in Azure IoT Central.
For more information about the Raspberry Pi Python sample, see the Readme file on GitHub.
Use the Web browser in the Raspberry Pi desktop to navigate to the Azure IoT Central firmware releases page.
Download the zip file that contains the most recent firmware to your home folder on the Raspberry Pi. The file name looks like
To unzip the firmware file, use the File Manager in the Raspberry Pi desktop. Right-click the zip file and choose Extract here. This operation creates a folder called
RaspberryPi-IoTCentral-X.X.Xin your home folder.
If you don't have a Sense Hat board attached to your Raspberry Pi, you need to enable the emulator:
- In File Manager, in the
RaspberryPi-IoTCentral-X.X.Xfolder, right-click the config.iot file and choose Text Editor.
- Change the line
- Save the changes and close Text Editor.
- In File Manager, in the
Start a Terminal session and use the
cdcommand to navigate to the folder you created in the previous step.
To start the sample application running, type
./start.shin the Terminal window. If you are using the Sense HAT Emulator, its GUI displays. You can use the GUI to change the telemetry values sent to your Azure IoT Central application.
The Terminal window displays a message that looks like
Device information being served at http://192.168.0.60:8080. The URL may be different in your environment. Copy the URL and use the Web browser to navigate to the configuration page:
Enter the device connection string you made a note of when you added a real device to your Azure IoT Central application. Then choose Configure Device. You see a message Device configured, your device should start sending data to Azure IoT Central momentarily.
In your Azure IoT Central application, you see how the code running on the Raspberry Pi interacts with the application:
- On the Measurements page for your real device, you can see the telemetry sent from the Raspberry Pi. If you are using the Sense HAT Emulator, you can modify the telemetry values in the GUI on the Raspberry Pi.
- On the Properties page, you can see the value of the reported Die Number property.
- On the Settings page, you can change various settings on the Raspberry Pi such as voltage and fan speed. When the Raspberry Pi acknowledges the change, the setting shows as synced in Azure IoT Central.
Now that you have learned how to connect a Raspberry Pi to your Azure IoT Central application, here are the suggested next steps: