With this project, you can ask Alexa, if your door is open. It uses a magnetic sensor attached to ESP8266 to do detect if the door is open. Alexa skill can access the information using AWS Lambda function, Azure REST API, and SignalR via Raspberry Pi. When a user asks Alexa the state of the door, it invokes a lambda function. The function calls a REST API method hosted in Azure. The REST API method uses SignalR technology to query Raspberry Pi, which in turn requests that information from ESP8266.
(In case you are wondering, Signal R is revolutionary Microsoft technology that allows a server to call a method on the client. The underlying infrastructure takes care of handling the protocols and actually making calls.)
Here is the overview of different components and how they work together.
Hall Effect Sensor and ESP8266A magnet is attached to a garage door. The Open/Close state of the door can be detected by its proximity to a Hall Effect sensor (A3144). The sensor is attached to ESP8266 that hosts a web server on the home Wi-Fi.
When a query is performed on the web server, it checks the state of the Hall Effect sensor and returns the corresponding door state to the caller (Raspberry Pi)
Raspberry Pi (Window IoT Core)This acts as a hub between the device on the home network (ESP8266) and the cloud host (Azure). This allows secure communication to the cloud as well as ability to become a Signal R Client. The app running on the device lets user register IP address of ESP8266. The app then registers itself with the SingalR host in Azure. This enables Azure to invoke a method on the Raspberry Pi.
When the method is invoked, Raspberry Pi queries the ESP8266 Webserver and returns the value via Azure Storage Queue.
Azure REST and SignalRAzure REST API listens to the queries from the authorized callers, validates the caller and calls a utility that obtains data from Signal R client. The data is returned to the caller.
Signal R has a limitation ie., it can invoke a method on the client, but it cannot retrieve a value from it. The utility addresses the problem by using Azure Storage Queue. When called, the utility creates a GUID and calls client passing the GUID. It then waits peeking the queue to see, if the message with the GUID has arrived. 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 Lamba function)
Alexa Skill & AWS Lambda FunctionWhen a user invokes the Door Check skill, it calls corresponding lambda function. The function creates a request with appropriate authorization key. The request is sent to Azure RESP 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 corresponding text that is read to the user by Alexa.
iOS, Android and UWP app(s)This is written using Xamarin forms to check the status of the door from a phone. It calls REST API hosted in Azure and displays the result to the user.
Make, Configure and RunIt is pretty easy to build the hardware as per the schematics. Keep in mind that the sensor requires more than 4.5v of supply. So the Sparkfun board needs to be powered by USB port.
Build and deploy Azure REST API. This will give you the base address of the cloud. Update its authorization key.
The Lambda function and in the UWP app should be updated with this value. The lambda function has a default timeout of 3 sec. You may need to increase that if your internet is slow.
In order for the system to get running, start the ESP8266 and note it’s IP address from the Serial monitor.
Register the device with UWP app. This will register Raspberry Pi with the Signal R and ESP8266 with Raspberry Pi.
This should be ready to run.
Comments