This document describes the process of setting up a Raspberry Pi 2 device to connect to an Azure IoT hub.
## Requirements- SSH client on your desktop computer, such as PuTTY, so you can remotely access the command line on the Raspberry Pi.
- Required hardware:
- Raspberry Pi 2
- 8GB or larger MicroSD Card
- USB keyboard
- USB mouse (optional; you can navigate NOOBS with a keyboard)
- USB Mini cable
- HDMI cable
- TV/ Monitor that supports HDMI
- Ethernet cable or Wi-Fi dongle
You may wish to consider a Starter Kit such as CanaKit that includes some of these hardware requirements.
## Before you begin Before you begin you will need to create and configure an IoT hub to connect to. 1. [Set up your IoT hub][setup-iothub]. 1. With your IoT hub configured and running in Azure, follow the instructions in [Connecting your device to an IoT hub][provision-device]. 1. Make note of the Connection String for your device from the previous step.## Prepare the Raspberry Pi 2Note: You can skip this step if you just want to build the sample application without running it.
-
Install the latest Raspbian operating system on your Raspberry Pi 2 by following the instructions in the NOOBS setup guide.
-
When the installation process is complete, the Raspberry Pi configuration menu (raspi-config) loads. Here you are able to set the time and date for your region and enable a Raspberry Pi camera board, or even create users. Under Advanced Options, enable ssh so you can access the device remotely with PuTTY or WinSCP. For more information, see https://www.raspberrypi.org/documentation/remote-access/ssh/.
-
Connect your Raspberry Pi to your network using an ethernet cable or by using a WiFi dongle on the device.
-
You need to determine the IP address of your Raspberry Pi in order to connect over the network. For more information, see https://www.raspberrypi.org/documentation/troubleshooting/hardware/networking/ip-address.md.
-
Once you see that your board is working, open an SSH terminal program such as PuTTY on your desktop machine.
-
Use the IP address from step 4 as the Host name, Port=22, and Connection type=SSH to complete the connection.
-
When prompted, log in with username pi, and password raspberry.
-
Create a root account using the following command
sudo passwd root
and choosing a new password:
The root account is necessary in order to install some libraries required by the device SDK.
## Build the sample application on the deviceRun the following commands in the terminal window connected to your Raspberry Pi.
-
Download the Azure IoT device SDK to your Raspberry Pi:
git clone https://github.com/Azure/azure-iot-sdks.git
-
Confirm that you now have a copy of the SDK under the directory ./azure-iot-sdks. Then cd to the directory:
cd azure-iot-sdks
-
Prepare your environment by running
sudo ~/azure-iot-sdks/c/build_all/linux/setup.sh
-
Edit the file ./c/serializer/samples/simplesample_amqp/simplesample_amqp.c and replace connection string placeholder with the connection string you obtained in the "Connecting your device to an IoT hub" step above. (You can use the console-based text editor nano to edit the file):
static const char* connectionString = "[device connection string]";
Note: You can skip this step if you only want to build the samples without running them.
-
Build and install the Apache Proton library:
sudo ./c/build_all/linux/build_proton.sh --install /usr
-
Build a few libraries upon which the samples depend:
sudo ~/azure-iot-sdks/c/build_all/linux/build_paho.sh
-
Finally, build the sample applications:
./c/build_all/linux/build.sh
-
Run the simplesample_amqp sample:
~/cmake/serializer/samples/simplesample_amqp/simplesample_amqp
This sample application sends simulated sensor data to your IoT Hub.
## Tips- On Windows, you can use the Device Explorer to see the data your device is sending and receiving.