IoT Hub Raspberry Pi 3 Client application

por Xin Shi
Última actualización: 21/08/2017
Editar en GitHub

This repo contains the source code to help you get started with Azure IoT using the Microsoft IoT Pack for Raspberry Pi 3 Starter Kit. You will find the full tutorial on

This repo contains an arduino application that runs on Raspberry Pi 3 with a BME280 temperature&humidity sensor, and then sends these data to your IoT hub. At the same time, this application receives Cloud-to-Device messages from your IoT hub, and takes actions according to the C2D command.

Set up your Pi

Enable SSH on your Pi

Follow this page to enable SSH on your Pi.

Enable SPI on your Pi

Follow this page to enable SPI on your Pi

Connect your sensor with your Pi

Connect with a physical BEM280 sensor and LED

You can follow the image to connect your BME280 and a LED with your Raspberry Pi 3.


You can use the application to simulate temperature&humidity data and send to your IoT hub. 1. Open the config.h file. 2. Change the SIMULATED_DATA value from 0 to 1.

Running this sample

Install Azure IoT SDK

Install all packages by the following command:

grep -q -F 'deb vivid main' /etc/apt/sources.list || sudo sh -c "echo 'deb vivid main' >> /etc/apt/sources.list"
grep -q -F 'deb-src vivid main' /etc/apt/sources.list || sudo sh -c "echo 'deb-src vivid main' >> /etc/apt/sources.list"
sudo apt-key adv --keyserver --recv-keys FDA6A393E4C2257F
sudo apt-get update
sudo apt-get install -y azure-iot-sdk-c-dev cmake libcurl4-openssl-dev git-core
git clone git://
cd ./wiringPi

Build the sample code

Build the sample code by the following command:

cmake . && make

Run your client application

Run the client application with root priviledge, and you also need provide your Azure IoT hub device connection string, note your connection should be quoted in the command.

sudo ./app '<your Azure IoT hub device connection string>'

Send Cloud-to-Device command

You can send a C2D message to your device. You can see the device prints out the message and blinks once receiving the message.

Send Device Method command

You can send start or stop device method command to your Pi to start/stop sending message to your IoT hub.