Alexa, Is My Garage Door Open?

How many times have you thought in your bed (or after driving a couple of blocks), is my Garage door open? It can be checked by attaching a magnet to your garage door. Hall Effect sensor attached to a Microcontroller can sense it. Alexa can query the microcontroller for the status.

Here is the proof of concept with a magnet, ESP8266, Raspberry Pi and Alexa.

 

The remaining article explains how to get that status from your IOT device.

It is common patterns that the “things” generate data, store it in the cloud either directly or via a hub. When a user seeks data, it is provided by Mobile Apps/Web Apps/BI analytics etc. In this use case, the app needs to request fresh data, wait for it to arrive and return the data to the caller.

The end to end solution cannot be provided by a single stack of technology (unless you are willing to manage your own “lambda equivalent” host and SSL on Raspberry Pi). Here is the stack of technologies used.

Stack

Signal R is the key technology behind it that enables a server to call a method on the client. This technology (or equivalent) is not available on Amazon AWS. So it needs to be hosted on Azure and be invoked by AWS Lambda. On the device side, ESP8266 does not have the ability to handle Signal R and the SSL stack. So Raspberry Pi acts as a Hub on the home network that handles secure communication with Azure for Signal R and plain text communication with ESP8266 on home Wi-Fi.

Alexa Skill & AWS Lambda Function

When a user invokes the Door Check skill, it calls the corresponding lambda function. The function builds a request with appropriate authorization key. The request is sent to Azure REST API that in turn obtains the status of the door from Raspberry Pi and returns it to the lambda function. Lambda function converts it to the corresponding text that is read to the user by Alexa.

Azure REST API and SignalR

Azure REST API validates the caller and obtains data from the client using Signal R. However Signal R technology cannot be used out of the box in this case.

Signal R has an inherent limitation. It can invoke a method on the client, but it cannot retrieve a value from the client. This limitation is addressed here by “GarageDoorHubUtil”.

When called, the utility creates a GUID and calls client (i.e. Raspberry Pi) passing the GUID. It then passes the GUID to “QueueUtil” that waits for the message with that GUID to arrive in the queue. When the appropriate message arrives, it processes the message to retrieve the value sent by the client. The value is returned to the REST controller and effectively to the caller (i.e. AWS Lambda function)

Raspberry Pi (Window IoT Core) & ESP8266

Raspberry Pi acts as a hub between the device on the home network (ESP8266) and the cloud host (Azure). This allows secure communication with the cloud as well as ability to become a Signal R Client. When GarageDoorHubUtil invokes “CheckGarageDoor” method on the Raspberry Pi, it requests the information from ESP8266 via HTTP GET. ESP8266 reads and returns the Hall Effect sensor value.

The value is combined with the provided GUID and added to Azure Storage Queue. Azure utility that is waiting for this message, retrieves it.

Effectively, the Sequence diagram for the entire interaction is as follows:

SequenceDiagram

If you are interested in building this project the details are described here:

https://www.hackster.io/sameerk/is-my-garage-door-open-81f3b3

The source code for all layers is on GitHub:

https://github.com/sameerkapps/AlexaCheckGarageDoor

If you have any questions, please ask them in the comments.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s