Thursday, January 14, 2016

Using Azure IoT Suite from Linux (Ubuntu 14.04)

Hi Folks,

Microsoft is providing an Open Source SDK to address the Azure IoT Hub and Suite, that is compatible Linux, Windows and OSLess systems for various languages such as C, C#,...
The repository is accessible on GitHub : https://github.com/Azure/azure-iot-sdks/

When using this repository and projects there are few pre-requisites, and the details below are for an Ubuntu 14.04 system.



Pre-requisites

cmake 3.x installation
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:george-edison55/cmake-3.x
sudo apt-get update
sudo apt-get install cmake

gcc 4.9 installation
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

cloning the SDK repository
git clone --recursive https://github.com/Azure/azure-iot-sdks.git
cd azure-iot-sdks
git submodule init
git submodule update

You also have to ensure that you have a valid Azure account and provision a solution into the Azure IoT Suite : https://www.azureiotsuite.com/

Building the samples

After satisfying the pre-perquisites, you are ready to build sample applications
cd c/build_all_linux
./setup.sh
./build.sh

Now you should be ready to use the samples applications, but don't forget to update the device and Azure credentials in the sample applications.

Identify the device parameters

Before being able to push data to your Azure IoT Suite solution, you have to create a new device or identify existing devices. When creating a solution, by default the Azure website have few simulated devices defined and generating random Temperature and Humidity values. But you can also add your own devices in order to manage real devices. Those devices are identified by a name and Shared Key to ensure that devices are trusted devices.

Create a new device

To add a new device to your remote monitoring solution, complete the following steps in the solution dashboard:
  1. In the lower left-hand corner of the dashboard, click Add a device.
  2. In the Custom Device panel, click on Add new.
  3. Choose Let me define my own Device ID, enter a Device ID such as mydevice, click Check ID to verify that name isn't in use, and then click Create to provision the device.
  4. Make a note the device credentials (Device ID, IoT Hub Hostname, and Device Key), your client application will need them to connect your device to the remote monitoring solution. Then click Done.
  5. Make sure your device displays correctly in the devices section. The status is Pending until the device establishes a connection to the remote monitoring solution.

Configure the sample application

On your Linux machine, open and edit the remote_monitoring.c file located in c/serializer/samples/remote_monitoring/.
And fill in the banks on line 20 using the information from your device created previously in Azure IoT Suite solution:
static const char* deviceId = "[Device Id]";
static const char* deviceKey = "[Device Key]";
static const char* hubName = "[IoTHub Name]";
static const char* hubSuffix = "[IoTHub Suffix, i.e. azure-devices.net]";

Once modified, the save and build the project as performed before.

Run the remote-monitoring application

From a terminal window launch the remote monitoring application.
~/cmake/serializer/samples/remote_monitoring/remote_monitoring

Check the results

The dashboard in the remote monitoring solution enables you to view the telemetry that your devices send to IoT Hub.
  1. In your browser, return to the remote monitoring solution dashboard, click Devices in the left-hand panel to navigate to the Devices list.
  2. In the Devices list, you should see that the status of your device is now Running.
  3. In the dashboard, select your device in the Device to View drop-down to view its telemetry. The telemetry from the sample application is 50 units for internal temperature, 55 units for external temperature, and 50 units for humidity. Note that by default the dashboard displays only temperature and humidity values.

Enjoy!

-Nicolas

12 comments: