services | platforms | author |
---|---|---|
iot-hub |
Nodejs |
shizn |
This repo contains the source code to help you get familiar with Azure IoT using the Microsoft IoT Pack for Raspberry Pi 3 Starter Kit. You will find the lesson-based tutorials on Azure.com.
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 message from your IoT hub, and takes actions according to the C2D command.
Follow this page to enable SSH on your Pi.
Follow this page to enable I2C on your Pi
Check your nodejs version on your Pi:
node -v
If your nodejs' version is below v4.x, please follow the instruction to install a new version of nodejs
curl -sL http://deb.nodesource.com/setup_4.x | sudo -E bash
sudo apt-get -y install nodejs
You can follow the image to connect your BME280 and a LED with your Raspberry Pi 3.
Default sensor type is set to DHT sensor. If you are using BME280 you can change it in the config.
- Open the
config.json
file. - Change the
sensorType
value to "Bme280"
You can use the application to simulate temperature&humidity data and send to your IoT hub.
- Open the
config.json
file. - Change the
sensorType
value to "SimulatedSensor"
Install all packages by the following command:
npm install
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 node index.js '<your Azure IoT hub device connection string>'
You can send a C2D message to your device. You can see the device prints out the message and blinks once receiving the message.
You can send start
or stop
device method command to your Pi to start/stop sending message to your IoT hub.