Professional Documents
Culture Documents
Contact Information:
Phone: +82-10-6876-6805
Email: faisal.avan@Hotmail.com
Table of Contents
S.No Topic
3. Set up Raspberry Pi
4. Click Save
Register a device in the IoT hub for your device (2/2)
5. After the device is created, open the device in the Device Explorer pane.
6. Make a note of the primary key of the connection string.
Note:
Device Id will be used to connect raspberry pi to IoT hub. We will need Connection
String and Shared Access Key.
Set up Raspberry Pi
• Connect the sensor to Pi, use the breadboard and jumper wires to
connect an LED and a BME280 to Pi as follows.
• BME280 is a sensor for temperature, barometric, pressure, and
humidity. Following table shows connecting hardware
Module PCB Desc GPIO Header Pins
VCC 3.3V P1-01
GND Ground P1-06
SCL 12C SCL P1-05
SDA 12C SDA P1-03
Run a sample application on Pi (1/4)
1. Connect to your Raspberry Pi with IP of the Raspberry Pi
one of the following SSH clients
from your host computer: We
have used PuTTY to access
Raspberry Pi remotely.
2. Make sure SSH is enabled in
Raspberry Pi
3. The default Username is “pi” and
password is “raspberry”
4. To enable SSH in raspberry pi
Follow the following steps
1. Open Command Terminal
2. sudo raspi-config
3. Select Interfacing Option
4. Select P2 SSH
5. Select Enable and Click OK
Run a sample application on Pi (2/4)
• To Find the ip of Raspberry Pi
• Connect the Raspberry pi with the Internet
• Open Command terminal
• Write the following Command
• Sudo ifconfig
• Note down the IP of the raspberry pi to connect via SSH
Run a sample application on Pi (3/4)
2. First check nodejs and npm To check
node .js version run the following
command
sudo nodejs --version
sudo npm --version
If node.js is not install, then install the
latest version of node.js and npm by
running following command.
sudo apt-get install nodejs
sudo apt-get install npm
If Node.js version is lower than 4.x then
run the following command
(node –v; curl -sL http://deb.nodesource.com/setup_4.x |
sudo -E bash; sudo apt-get -y install nodejs)
3. First Install git on raspberry pi, To
Install git run the following command
sudo apt-get install git
Then Clone the sample application.
(git clone https://github.com/Azure-Samples/iot-hub-
node-raspberrypi-client-app)
Run a sample application on Pi (4/4)
4. Install all packages for the
sample.
The installation includes
• Azure IoT device SDK
• BME280 Sensor library
• Wiring Pi library.
cd iot-hub-node-raspberrypi-client-
app
sudo npm install
Configure the sample application (1/4)
5. Open the config file by running the
following commands: We have used Nano
editor to edit config file.
sudo nano config.json
There are two items in this file you can
configure.
1. The first one is interval, which defines the
time interval (in milliseconds) between
messages sent to the cloud.
2. The second one is simulatedData, which is
a Boolean value for whether to use
simulated sensor data or not.
Configure the sample application (2/4)
6. If you don't have the sensor,
set the simulatedData value to
true to make the sample
application create and use
simulated sensor data.
7. Change the Device ID. Device
ID is the ID which we Added in
the Microsoft Azure IoT Hub.
Refer To Slide 7 to know the
Device ID
Now Save by following
Command
Ctrl + 0
And press Enter
Now exit nano editor by
following command
Ctrl + X
Configure the sample application (3/4)
8. Run the sample application by running the following
command:
sudo node index.js '<YOUR AZURE IOT HUB DEVICE CONNECTION STRING>‘
Refer To Slide No. 6 for connection string
sudo node index.js 'HostName=my-hub.azure-
devices.net;DeviceId=raspberry-
pi;SharedAccessKey=OhJ3uXxxK54BDEI9u/jO5iCmG051dOeGBJuOP/r3
ZGI='
Have a “unable to determine hardware version” error.
Configure the sample application (4/4)
9. Solution: Solve the error by
updating the firmware to the latest
version, reverting fixed it using this
command:
sudo rpi-update
52241088c1da59a359110d39c1875cda5
6496764
Then it is able to send data to
Azure IoT Hub:
Monitor device-to-cloud messages using iothub-explorer
To monitor messages that are sent from your device to your IoT hub, follow these steps:
1. Open a console window (bash)
2. Run the following command:
iothub-explorer monitor-events <device-id> --login "<IoTHubConnectionString>“
Note: Refer To Slide 6 for Connection String and SharedAccessKey. Refer to Slide 7 for Device
ID.
iothub-explorer monitor-events raspberry-pi --login "HostName=my-hub.azure-
devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=GZNNngcIvMi2B9mt6XksJ
B99p83QtgfCPwvIYQPbM9A="
Hostname my-hub.azure-devices.net
Device ID raspberry-pi
• Contact Information:
• Phone: +82-10-6876-6805
• Email: faisal.avan@Hotmail.com