Principal concept of device to device (D2D) messaging

Device to device communication with IoT Hub

In the figure above the principal device to device communication with IoT hub can be seen. The goal for this project is to send a message from one device to another device. The Raspberry Pi sends a message to the Philipps Hue when he sees the Raspberry Pi face recognition program. The Philipps Hue receives the message and changes the color according to the recognized person.

This messaging process needs to be done in combination with the IoT Hub. In detail a message from the Raspberry Pi (Device 1) is sent to a custom endpoint of the IoT Hub. This message is stored in a service bus queue or a storage container or something similar and then processed by an azure function or logic app which establishes a connection with the target device (Device 2).

In this project it is possible to create a face recognition with the raspberry pi and when a face gets detected a message is sent to the IoT hub. It’s possible to send messages from the IoT hub to the raspberry pi. But it could not be possible to create a device to message message, even though a message could be stored in a storage container and the logic app could react to this message.

Philips Hue – The Actuator

Introduction –
These smart bulbs are Wi-Fi enabled color changing LED lamps and white bulbs. It uses the Zigbee protocol to communicate and can also be controlled via the Philips Hue app (available in Android Play Store and Apple App Store) over Wi-Fi via a Hue bridge. This smart bridge connects to the LED bulb and then the 600 lumens LED connects to the Hue app on the phone. Through the app, you can not just turn on and off the light when you leave home, but you can customize the color of the light. One of the advantages of the smart bulbs is that they fit into the existing bulb.

We make use of Philips Hue in this project as an ‚Actuator‘. In order to establish a communication between  Microsoft  Azure and Philips Hue, we have made use of the ‚Function Apps‘ featured in Azure.

Steps – 

1. Hue Setup –

As well known, Philips Hue can be used through its Philips Hue app (for Android) or through Apple Store. For our project, we have made several API calls. The same can be understood from the documentations in the official pages:

https://www.developers.meethue.com/documentation/getting-started

The procedure for using the API is slightly convoluted on the auth-part. Furthermore, apart from the Clip Debugger tool mentioned, these API calls also work from other tools like Postman.

2. Azure Setup – 

In order to connect Azure and Philips Hue, we will do a queue-triggered function that will in turn do an HTTP-based call to the Hue Bridge.

For this, we first create an Azure Storage Queue: In Microsoft Azure, create a storage account and add a new queue under Queue Service. Queues were used as we did not need to send / receive large amounts of messages in order to test our connection. So, it’s straightforward to get through the Azure portal.

queue

3. Function Setup –

The next step is to create a function app in Microsoft Azure. For this, adopt the following steps –

i. Click on ‚Create a new resource‘.

ii. On the search box, type function app. Then click Create.

iii. Fill in the app name. In order to link the app to your resource group, click on ‚Use existing‘ under Resource Group field and choose the required Resource group. Then click Create.

iv. Once the function app is created, navigate to the function app. In order to create a queue triggered function, the following official documentation may be referred –

https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-storage-queue-triggered-function

v. The following is the sample code snippet –

Function app_queue trigger

vi. In order to test the function, add few messages to the queue and run the function. The logs have been read from the queue.

Conclusion – 

In a nutshell, through Microsoft Azure, we create a function app created in the Azure portal in order to control the lights.

We saw that Philips Hue Lights could also be accessed from the Internet (either through API or through codes written in Microsoft Azure) instead of Android apps alone.