Saturday, November 17, 2012

Homebrew webcam security

There are a million articles on the toobs about homebrew webcam security, but since I've christened my own I thought I'd at least post the details in case anyone else out there is worried about getting burgled or their house flooding or pipes freezing while away. I know way too many people who have had the above happen to them. Anyway...

My setup is a franken donor Dell laptop inherited from Andrea who was going to run it over with her car, with a Logitech 9000 pro webcam. The laptop has been rained on, keyboard melted & replaced (don't ask), monitor brackets are broken, and the power cable is somehow brutally twisted, but it still works like a champ with some love.

It's running an old flavor of ubuntu I stopped updating in grad school, onto which I installed motion, a motion detector software. Basically you plug in the webcam, point it to where you want to watch, and walk away. But what is involved in configuration?

It boils down to just a couple of config files and scripts:

  • motion.conf (configures the motion program)
  • arm.sh
  • notify.sh
  • dog.wav
I left the motion.conf essentially default as installed except for a few changes. I had to adjust the sensitivity some to keep it from text bombing me when the minute hand moves on the clock, and also made the following other minor changes:

  1. snapshot_interval 1800 # seconds = a half hour

    This takes a record of what it can see every half hour so that I can tell if it goes down for any reason. I also have a climate monitor in the scene so I can tell if my pipes are freezing when I'm on vacation and call a friend to turn my heat on.
  2. on_event_start /usr/local/motion/notify.sh & sleep 10 && mplayer /usr/local/motion/dog.wav

    The notify script lets me know when motion is detected.

    #!/bin/bash
    tail ~/motion/motion.log | mailx -s 'motion event occurred' user@gmail.com
    echo 'the dog is barking' | mailx -s 'motion event occurred' 9491234567@txt.att.net

    The first line just tells the shell what interpreter to use. The second line sends me an email with the last ten lines of the log file. The third line sends a text message to my phone so that I can look through the photos and see if there's actually anything interesting going on.

    As the notify is occurring in the background (&) the system waits 10 seconds (sleep 10), then (&&) plays the sound of an incredibly angry dog barking. I have the speakers and laptop upstairs, and the camera hidden downstairs at the end of a 50ft active boosted USB extension watching the entryway so when someone comes inside a) I'll see them, and b) the 'dog' will hopefully scare them away. The active USB extension is reported to reduce the effective bandwidth somewhat, but with only one webcam at the end it seems to work OK.
  3. on_picture_save scp %f user@host:motion/
    This command secure copies all the images through ssh protocol to a remote host, just in case the dog doesn't scare them off and they steal my computer. This isn't really the ideal way to copy the files, since if the scp happens slower than the framerate it will stack up numerous instances of scp and they will all transfer very slowly. The best move would be to sequentially copy the frames one at a time, which would be just a little more complicated, but it seems to work OK for now.
  4. on_event_end rsync -aPz /usr/local/motion/* user@host:motion/
    After the motion has stopped, this command does one more final run to make sure all the files are copied over. Sometimes one or more copy during acquire fails, so this makes sure those parts aren't left out.
When I leave, I just arm it with: sleep 60 && /usr/local/motion/arm.sh so that it gives me a minute to leave without setting off the dog. The script just contains: motion 2>&1 | tee -a /usr/local/motion/motion.log which redirects standard error to standard output and pipes the output to tee, which copies it to the terminal and to a logfile for later review.

At ~$30 per camera, this system is way cheaper and more customizable than most other monitoring systems around, and the ability to make funny noises is a riot. Just think, you could arm your office to spook the janitor, or Rick-roll someone, or all sorts of other fun shenanigans. 

2 comments:

Unknown said...

One burglar caught!
http://intermittentshorts.blogspot.com/2013/01/homebrew-webcam-security-followup.html

Unknown said...

http://superuser.com/questions/431759/using-multiple-usb-webcams-in-linux