This tutorial shows how to develop and compile a simple device app written in C and running on Raspberry Pi to send telemetry data to Azure IoT Hub.
- How to install the development environment.
- How to create an IoT Hub and register a ESP32 device.
- How to send sample data to your IoT hub.
- A Raspberry Pi device with Raspbian running on it.
- A computer running Windows 10, Ubuntu 18.04+ or macOS 10.10+.
- An active Azure subscription. Activate a free 30-day trial Microsoft Azure account.
-
Within VS Code, press
F1
to open the command palette, then type and select Azure IoT Device Workbench: Create Project.... -
Enter the name of your project.
-
Select Embedded Linux (Preview) from device platform list.
-
Select the dev container based on your target device, in this sample, select Azure IoT Device C SDK for armv7 Linux for Raspberry Pi 3 Model B+ running Raspbian.
-
Select No to open the configured project in remote container.
-
The first time you use a container, it takes around 1 to 3 minutes to download and prepare the dev container. Click the details link on the notification for the progress:
-
Once the dev container is ready, you can see the status in the status bar and output window:
-
The
main.c
file is the source file that contains the application logic. You can modify or add your own code in this file: -
To compile the code, press
F1
, type and select Azure IoT Device Workbench: Compile Device Code from the command palette. -
The cross-compiling of the code happens in the dev container. Once it's done, it shows the notification:
-
The compiled binary file is located in the
.build
folder.
-
Before you upload the executable binary file to the target device, make sure:
- The running OS on the device is correct (e.g. Raspbian running on Raspberry Pi 3 Model B+).
- SSH is enabled on the device. Follow these instructions to do so.
- Get the IP address of the device so that you can deploy the compiled binary to the device using SSH.
-
In VS Code, press
F1
, type and select Azure IoT Device Workbench: Upload Device Code from the command palette, then select Manual setup and enter the IP address, port, user name and password to deploy the compiled binary via SSH to Raspberry Pi:
-
To start running the deployed binary, SSH into your Raspberry Pi device. You can follow these instructions to do so.
-
You need to pass the device connection string as a parameter to run the app, follow this guide to use Azure IoT Hub Toolkit to do so.
-
Run the below commands to enable use to
openssl 1.0.2
on Raspberry Pi:apt-get install libssl1.0 libssl1.0-dev sudo ln -s /usr/lib/arm-linux-gnueabihf/libssl.so.1.0.2 /usr/lib/libssl.so.1.0.0 sudo ln -s /usr/lib/arm-linux-gnueabihf/libcrypto.so.1.0.2 /usr/lib/libcrypto.so.1.0.0
We use Azure IoT Device C SDK via Vcpkg, while currently it only supports
openssl 1.0.2
.openssl 1.1.1
is not supported yet. See issue 1341 and issue 4267. -
Run
azure_iot_app [device connection string]
and you see the Raspberry Pi start sending telemetry data to the Azure IoT Hub: -
To verify the reception of the data, use Azure IoT Hub Toolkit, right click on the device and select Start Monitoring Built-in Event Endpoint. In the output window, you can see that IoT Hub gets telemetry data sent from Raspberry Pi: