Who’s There


Ingredients:

  • Android Device with cameras and internet access and accelerometer
  • Android Device with internet access
  • Webserver for storing pictures
  • Free Urban Airship Account
  • Google Account (for using Google Cloud Messaging for Urban Airship)
  • Wifi
  • Something to attach the android device to the peep hole

Problem:

When I’m at home I’m usually in the living room. Due to the odd shape of my apartment its rather difficult to hear when someone is knocking at my front door, or a neighbors. I wanted to see if I could repurpose a secondary android phone to notify me when I’m either not home or in another room when someone knocks at the front door.


Overview:

One camera is attached to the peephole and takes a picture when the accelerometer has changed. It then uploads the picture to my server which returns the url of the posted image. The cell phone then posts to Urban Airship which in turn sends a push notification to my personal phone. When I click on the notification a webview opens up showing me the picture that was taken.

Challenges:

In android the battery drains really quickly when using the camera and sensors so the challenge is to conserve as much energy is possible. For that reason I selected to use an Android Service since it doesn’t require the screen to be on while running. Note some sources indicate that it isn’t possible on all Android Devices to take pictures from a Service. If I’d want to use this long term I’d end up plugging in the phone so I don’t have to worry about power consumption.

The accelerometer is easily set off. Because of that it is easy to attempt to take another picture while one is already in progress. Which causes an exception to be raised. I ended up using synchronized java attribute to prevent duplicate picture attempts too closely. I also added a timeout of five minutes to prevent batch pictures.

Suggested upgrades:

Some phones take really big pictures and it delays the upload. I’d recommend compressing before uploading. Adding a service that returns a json list of the images on the server etc.

Code:

Coming soon, look for it on my Github.


Leave a Reply

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