Connecting Raspberry Pi to Azure IoT Central
Although Raspberry Pi can be used as a basic computer; it can also be used as a sensor node. You can connect sensors to Raspberry Pi, and then send the telemetry data to Azure IoT Central easily.
Please note using Raspberry Pi 3 as a sensor node might be costly, so you may consider using Raspberry Pi Zero or other low-cost devices if you're planning more than a few devices in your system.
- Raspberry Pi running with Raspbian OS
- Azure IoT Central account
- Internet connection
We're going to use Python over Raspbian in this example for simplicity. To get started, first create a device template. (There is a post here describes creating device template.) Add "humidity", "pressure", and "temp" fields as telemetries. And then, add a real device from the device explorer.
Copy the code below to your computer.
From IoT Central device window, click Connect on the top-right of the device screen.
Grab scopeId, deviceId and primary key, fill the necessary parts on the "azureiot.py" file.
Install "iotc" Python client using the following command using SSH.
pip install iotc
Copy the "azureiot.py" file to your Raspberry Pi, and run it using the following command.
After a few seconds, you'll see a connected message on the terminal. Then, your Raspberry Pi will send telemetry continuously. You can see the data graph from the "Device Explorer" menu.
To quit the application, press CTRL+C