Completed Project Video:

Note: The first part of the video is our playful take on the interaction of the application. We developed this Alexa application while being 400km away from each other with our hardware being divided amongst us hence the difference in scenery when I go to open the door. The second part of the video shows that our Alexa project actually works and there isn't any editing tricks shown. Enjoy :).

Introduction

“Alexa, Who is at the Door?” is an Amazon Alexa skill set that utilizes Raspberry Pi and Firebase along with a facial recognition API to let you know who is knocking at your door.

After Alexa gets the approval to take a picture of the visitor’s face, it sends a command to the Raspberry Pi to take a picture of them using the camera module. The picture is then processed through a facial recognition API called “Kairos” which then determines whether or not the face is recognized, unknown, or not there at all.

After Alexa is taught a new face, the person is given a name by the user which is then saved in the database. It can be re-taught several times in each occasion that the visitor comes to your home. This way, the visitor’s face can be recognized in different conditions such as brightness, darkness, or a slight change in appearance of the individual. This also improves Alexa’s speed at which she recognizes each new friend that is added to the database.

Setup the Raspberry Pi and Camera Module

One of the key components of this project is setting up the Raspberry Pi and the camera module properly because after all, we wouldn’t be able to see who has wandered up to our door! After installing the Raspbian operating system onto your pi from RP’s website, we’re going to need to need to install the latest kernel, GPU firmware and applications for Raspberry Pi. The RaspiCam Documentation provided on RP’s website makes this super easy for us.

Plug in the RaspiCam module into the Raspberry Pi.

Credits: raspberrypi.org

Step 1) Execute the following commands into your Raspberry Pi terminal to get started.

sudo apt-get update sudo apt-get upgrade

Step 2) Next, we need to enable RaspiCam camera support.

sudo raspi-config

Step 3) When the fancy GUI appears, use the arrow keys on your keyboard to move down to enable and hit the enter key to select it. After exiting raspi-config, you will be prompt to reboot your Pi. The enable option ensures that upon reboot the correct camera drivers will be running. To test that everything is working smoothly try the following command in your terminal.

raspistill –v –o test.jpg

If everything is going as planned, the Raspberry Pi display should show a 5-second preview from the camera’s perspective and you should see a little red dot appear in the top corner of the camera module. The terminal will output various informational messages as this is happening. After the picture is taken, it’ll be saved under in the file test.jpg which you can then open and view your marvellous picture!

If things aren’t working as they should be, the RaspiCam Documentation outlines a series of very descriptive troubleshooting methods that will help you get your Pi camera up and running in no time.

Setup Database and Configure Code Repository

For "Who's at the Door?", firebase was used as the connection between local and cloud communication. Both the lambda function and the Raspberry Pi are listening to the firebase DB (the lambda function only listens to firebase when it's triggered by Alexa Voice Services).

Based on messaging triggers sent by both the Lambda Function and the Raspberry Pi in the flow of this Alexa Skill, specific responses can occur on the Alexa and specific actions can occur on the Raspberry Pi.

Setting up your firebase service

Step 1) Create a firebase account or login with your google account at Firebase.

Step 2) Create a new project.

Step 3) Create a firebase security profile.

After accessing permissions, click on 'Service Accounts' (1) then click 'Create Service Account' (2).

A window should show up giving you some options to create your security profile. Start by first setting your service account name (1). Next name your Service account ID (2). Then check 'Furnish a new private key' (3) and choose JSON format (4). Click create when finished (5).

Once created, the security profile will download. Place this file in the github repository you have downloaded and re-name it something easy to remember.

Step 4) Configure your Real-Time Database. Start by clicking on 'getting started' in your firebase console.

Next, we have to setup the Real-Time DB. This can easily be done by importing this JSON (can be found in Github repository under db.json )

{ "Alexa" : { "Read" : "", "Write" : "" } }

Voila! The firebase is setup. Now let's move onto setting up Alexa and our Lambda Function.

Setup Repository Code

In index.js, change the APP_ID variable to your Amazon App ID found on the Alexa section of the developer console,

var APP_ID = '<Amazon APP ID HERE>';

In firebase.js and database.js, change the firebase.initializeApp function parameters databaseURL to your firebase Real-Time database URL (found on the firebase console) and serviceAccount parameter to the saved security profile you created above (.json format).

firebase.initializeApp({ databaseURL: '<firebaseURLhere>', serviceAccount: './<firebaseSecurityProfile>.json' });

Create a developer account at Kairos and replace the app_id and app_key parameters in firebase.js to the credentials on your Kairos developer account.

headers:{ 'Content-Type': 'application/json', 'app_id': '<KairosAppID>', 'app_key': '<KairosAppKey>' }

Now, zip up the files to get ready to push it to lambda. Zip index.js, database.js, responses.js, <SecurityProfile>.json, node_modules, AlexaSkill.js, and package.json.

Upload that zip to your Amazon S3 bucket. (to upload to lambda, the zip file is large).

Setup Alexa and Lambda

Create your lambda function

Skip this page.

Setup Alexa Skills Kit trigger and click next.

Next, name your function and choose to upload from Amazon S3 (large ZIP file).

From the uploaded zip from before, find its S3 link and copy it into the text input field shown.

Fill in the rest of the fields as follows:

Setting up the skill to test on the development console

Go to https://developer.amazon.com/home.html and sign on with your AWS account. Once logged in, Click on the Alexa tab.

Next, click on the Add a New Skill Button.

Then, fill out the input fields as follows below and click Next

Add the contents from IntentSchema.txt to the Intent Schema input text.

Add the contents from SampleUtterances.txt to the Sample Utterances input text and press the next button.

Fill in the Global Fields as shown below.

Your Alexa skill is now set up!!!

Test and Enjoy the Skill

On the Raspberry Pi terminal, type:

node firebase.js

Make sure the camera is setup on your door (or in-front of your face to test it). On the Amazon Developer Console, where your Alexa application exists. Copy your Lambda ARN into the the created Alexa skill and begin testing. Follow the flow shown in the demo video or the VUI to test the skill to its extent.

To test the responses, on the development console enter the following.

Have fun!!!

- Himel & Abbass