Alexa, Who’s At The Door?

Hardware components:
R8326274 01
Raspberry Pi 2 Model B
× 1
Echo
Amazon Alexa Amazon Echo
× 1
11868 00a
Raspberry Pi Camera module
× 1
Software apps and online services:
Dp image kit 02
Amazon Alexa Alexa Skills Kit
Firebase
Screen%20shot%202015 07 20%20at%206.10.26%20pm
Amazon Web Services AWS Lambda

Alexa, Whos At The Door

STORY

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

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.

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).

Schematics ofAlexa Whos At The Door

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

Create a developer account at Kairos and replace the app_id and app_keyparameters 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.

Read More: Alexa, Who's At The Door?


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top