Surveillance systems are often a necessary and expensive investment for many SMBs, so having a cheap do-it-yourself alternative that can make use of existing hardware would likely make many business owners quite excited. With a little bit of know-how and some time to tinker, anybody can empower themselves and their business with some added security. I put this idea to the test at home, though you could use the same logic for an SMB surveillance system (well, except most businesses don't have a guard dog).
Light bulb moment
For the past several years I have toyed with the idea of setting up a home surveillance system because of the growing rate of break-ins and burglaries in my area. Several of my neighbors have a surveillance system, and it has proven useful for them more than once. The other day I was thinking about this when it dawned on me that I already had everything I needed (except for some software) to set up a make-shift surveillance system in my living room.
By using one or two of my old Android phones, all I needed to do was run a constant power supply to the phones, mount them in spots that will have the most visibility of the inside of my house, and write an app that will continuously record video and dump the files to the location of my choice. The first thing I had to do was decide where to dump the video files.
Where to store the videos
My initial thought was to have my desktop upstairs act as a file server. I quickly realized this plan was flawed, because if someone broke into my house and stole my computer I wouldn't have access to the videos to review. This meant I'd have to store the videos off-site.
Then I remembered thinking the Dropbox API for Android looked incredibly easy to use. So I decided that for the first pass of this app I would upload the files to Dropbox to see how quickly that storage expires, and then determine if it would be manageable for me to occasionally clear out my Dropbox folder by hand to free up space. After all, I probably won't be running the surveillance video all the time; we have a pit bull that guards our house when we are in town, so the only time I feel like I need to monitor the house is when we go on vacation and can't leave our dog home.
The next decision I needed to make was how large to make each video file before attempting an upload. If I made the videos too small, it could be painful to go back and review them later. If the videos are too large, I risk the upload timing out. But since the phone would be running on my home Wi-Fi, I figured it should have a pretty solid Internet connection. I chose to make the files too large and tweak some settings until everything met expectations.
In order to start conceptually planning out the application, I needed:
- 1 Activity to perform the video recording
- 1 Service to execute the video uploading
The Activity was fairly easy to write; it just needed to get a handle on a Camera object and start/stop recording when appropriate. It also needed to get a full wake lock so the device stays awake the entire time. The Activity saves the video files on the device's SD card, which is where the Service will take over. I decided to make the Service a sticky service that always stays running in the background. When it starts running, it will:
- Check the folder on the SD card where the Activity has been writing the video files.
- Upload each file to Dropbox if the folder is not empty.
- After each file has successfully uploaded, delete it from the SD card and move on to the next file.
- When the folder is empty, have the thread sleep for a set amount of time and then repeat the process.
If all goes well, I have thought of some pretty neat extensions that I'd like to implement after I get the basics working. For instance, if I could figure out how to determine how much "noise" was in a video, at a certain threshold the device could send a push notification to me, alerting me that there is activity in your house. At that point, the ability to tap into a live video feed directly from the phone so I could actively monitor what was happening, or better yet, provide a live feed to the police, would be incredibly useful.
In my next post, I'll reveal how development went and share the code I write.
Kyle is a senior software engineer specializing in web/Android development living in Austin TX. He's a self-professed "gadget freak" whose passion for mobile devices drove him to jump into the mobile industry in 2010. He enjoys the fast-paced nature of the mobile tech industry, as it provides him constant opportunities to learn and tons of motivation to do some innovation of his own.