Keep Tab On Home Security With A Webcam And Twitter
Blog | Tech Blog | Secure Coding | Twitter | RSS Feed | Get Email Updates
Worried about someone breaking into your house in your absence? Or just need to keep a tab on who enters your room while you are away? Well, all you need is a webcam, a linux PC/laptop and a twitter account. And you are set for real time updates through twitter about all that goes on at your abode behind your back (can even receive a text message/sms on your phone). Keep reading for the very simple setup you need.
1.) Download and install "motion" on your computer. For ubuntu users, this is as simple as running
-
sudo apt-get install motion
2.) Setup your motion configuration file. (Usually at /etc/motion/motion.conf). There are quite a lot of options available. You might want to tweak it a lot according to ur needs later on but the most important ones that you can begin with are (leave the rest untouched for now):
2a.) Add/edit the option "target_dir" to point to the directory where you want to save the images of the event when motion is detected.
2b.) Add/edit the option "locate" and set it to "on" so that you get a nice square box around the detected moving object/person.
2c.) Add/edit the option "webcam_port" and set it to, say, "8000". Motion includes a mini http server so now, you can use it to view the actual images of the happening when you get the update and check for false alarms.
3.) Now, comes the most important part, about getting the update.
motion has an option called "on_motion_detected" and here you can specify any command or program that you want to run when motion is detected. To get the update on your twitter account, use one of the following three methods with this option.
3a.) Using curl. If you have curl installed in your system, then you can use the following value for the on_motion_detected option:
-
curl -u yourusername:yourpassword -d status=”Motion Detected! Check Immediately” https://twitter.com/statuses/update.xml
3b.) Using wget. If you don't have curl, you can even use wget for this. Use the following value:
-
wget -O - --user=YOURUSERNAME --password=YOURPASSWORD --post-data=”status=Motion Detected! Check Immediately” https://twitter.com/statuses/update.xml
3c.) Using my perl script. If you don't have curl as well as wget, you can even use my perl script (attached below) for this. The value will now be:
-
/path/to/script/twitter.pl "Motion Detected! Check Immediately"
4) Now connect your webcam and start motion (Just type "motion" on command line and press enter). Wait for someone to break in, or just roam around in front of the camera yourself and have fun as you receive a message on your phone about the "motion".
PS: For receiving a text message on your phone, you'll need to turn on the "Device Updates" option in your twitter account, otherwise you need to open the twitter web page to check the status.
The script: Twitter Updating Perl Script
Let me know if you put this to some other exciting uses or have any questions about the method described above.
© Shantanu Goel | Keep Tab On Home Security With A Webcam And Twitter
|
Liked this post? Get FREE Updates Subscribe to RSS feed |






This post has 44 comments
May 16th, 2008
I haven't written anything in a while, but a creative hack like this is a great catalyst. Keep up the good work. This is an excellent tutorial.
May 16th, 2008
For some users, I think this technique might be more accurate if the notification message was "Cat Detected! Check immediately!"
May 16th, 2008
Hey .... second post on Lifehacker ...
Cheers!
May 17th, 2008
@Amy: Thanks...
@John: Didn't get you...Do u mean, context based messages?
@Coolant: Thanks man..
May 17th, 2008
@Shantanu: I think John means that motion isn't the best criteria for an alert if you have pets moving around all day.
May 17th, 2008
@Chris: yeah, thats true..Basically how I am using it is with the inbuilt webserver capability of motion. If/when I get a message, I simply connect to my webcam images at myipaddress:someport through my phone or office PC's browser and check whats the cause of the motion. But apart from that I'd say it's very difficult to formulate the message acc to the object causing the motion.
Note: I have a dynamic ip address, so the script that I use gets my ip from the web and sends that to me as well in the message
May 18th, 2008
I've done everything in this guide, yet it won't send the updates to my phone. It updates on the site (I've added the device and everything, set up updates etc) but I can't follow myself and it doesn't send the updates to my phone...
May 24th, 2009
set up a secondary twitter account just for this purpose, then follow it.
May 18th, 2008
@blu: Oops, there is a small thing I forgot. What you need to do is create another account, and follow it, and send the tweets to that new account. Otherwise you can post direct messages to yourself (d yourusername message), that should also work.
May 19th, 2008
Motion is working, I set up two twitter accounts, one following the other, however motion is not posting the alerts to my 1st twitter account.I tried all 3 methods, any idea on what I'm doing wrong?
May 20th, 2008
@steven: Can you check if any of the commands are being run. I mean replace the twitter command by something like "touch ~/abc.txt" and see if on detecting motion the file is created in ur home directory or not.
May 20th, 2008
abc.txt was createdhere's the response when I run motion with curlscr@scr-desktop:~$ motion[0] Processing thread 0 - config file /etc/motion/motion.conf[0] Motion 3.2.9 Started[0] ffmpeg LIBAVCODEC_BUILD 3352064 LIBAVFORMAT_BUILD 3344896[0] Thread 1 is from /etc/motion/motion.conf[1] Thread 1 started[0] motion-httpd/3.2.9 running, accepting connections[0] motion-httpd: waiting for data on port TCP 8080[1] Not a V4L2 device?[1] Using VIDEO_PALETTE_YUV420P palette[1] Using V4L1[1] Started stream webcam server in port 8000[1] File of type 8 saved to: /home/scr/Webcam_Pictures/01-20080520091845.swf[1] File of type 1 saved to: /home/scr/Webcam_Pictures/01-20080520091845-01.jpgcurl: (6) Couldn't resolve host 'Detected!'curl: (6) Couldn't resolve host 'Check'curl: (6) Couldn't resolve host 'Immediatelyâ��'[1] File of type 1 saved to: /home/scr/Webcam_Pictures/01-20080520091846-00.jpg[1] File of type 1 saved to: /home/scr/Webcam_Pictures/01-20080520091846-01.jpg[1] File of type 1 saved to: /home/scr/Webcam_Pictures/01-20080520091847-00.jpg Tue May 20 12:51:58 +0000 2008 815714179 ”Motion web false false 14834776 sredd1701 sredd1701 false 1
May 20th, 2008
Steve: I found the issue. It seems that for many users this is causing a problem if they have spaces inside their "message" even if it is surrounded by quotes. A simple solution would be to use smthing like "MotionDetected" instead of "Motion Detected! Check Immediately", otherwise u can just hardcode the command and message into a shell script and just call that script instead.
May 20th, 2008
Thanks for the response. I figured that out about an hour ago myself, just didn't get around to telling you until now. Also, it may just be my phone service, but if I don't delete the text message when I get it, another message with the same text will not be received.
BTW, I'm using a cheap Logitech Quickcam Chat webcam, less than $20 and it worked ootb with Ubuntu Hardy!
The picture quality isn't great, But you get what you pay for.
Thanks again for all your help.
May 21st, 2008
Sorry to bother you again, and yes, I'm a real noob on linux, but I'm still having 2 problems. First when motion updates my twitter account, I don't always get a text on the update. This sounds like a twitter problem, so I'll pursue it there. Second, it seems that twitter doesn't update if the current message is the same as the previous one. Is there a way to rotate messages or send a message plus a random number to insure that twitter updates?
Also, if someone breaks in and steals my computer, I've lost all pics of him. Is there a way to have motion email the pics to my Gmail account?
May 21st, 2008
Steve: As u mentioned the first 2 are twitter problems. But we can work around the second problem. For that, instead of having the command itself in motion.conf, you can create a shell script (a simple text file with #!/bin/bash in the beginning and then ur command). And in the command you can append `date` to your "message". So everytime the current time will be added to msg making it unique. Call this script in ur motion.conf. Let me know if u need more help with this.
About the third issue. You can mail them easily using a command line mail client (like mutt) but you'll have to set it up. U can google for how to set it up to be able to send mail and then just add the proper command line for it in motion.conf (or in ur shell script so u get twitter update as well as mail.). Again, lemme know if u need more clarification.
May 22nd, 2008
As I said before, I'm new to Linux so I've never written any kind of script before. But now seems like a good time to learn something new! Well, I'm off to Google how to write shell scripts!
Thanks for all the great advice.
May 28th, 2008
That's pretty nifty.
May 30th, 2008
Nice piece of integration. For those with pets, it might be fun to set up the camera with a field of view that allows some inference about what the pet is up to (scratching at door, poking at food bowl, ..) - then the pet could have its own twitter account updating with its status.
June 17th, 2008
How do you know if your computer is linux or not?
June 17th, 2008
If you combine the motion program with the following script http://lifehacker.com/software/hack-attack/automatically-upload-a-folders-photos-to-flickr-262311.php , it can also post pictures to a flickr account, so you can automatically see the cause of the twitter update.
June 17th, 2008
PJ: was that a joke?
USP: That's a cool tip. Thanks. I'll see if I can collect some of the tips/discussions done here in comments and update the post with them. Some of the things included would be tips about different things that can be done and also how to use this in windows..
June 18th, 2008
Yeah, I had a brain lapse for a minute. Sorry
I know some things but I am still new to all of this.
June 19th, 2008
The problem in the twitter command ("Motion Detected") isn't the spaces, it has to do with the direct copy and paste of the command into Motion. When you copy and pase the command, delete the quotation marks that are in the command, and then manually type them back in with your keyboard.
June 25th, 2008
Awesome stuff !! I just configured motion at my house sitting in the office. I hope someone breaks in just so that I get to see this work
June 26th, 2008
Great tips! Hopefully this can be a cheap and easy way to improve home security.
August 25th, 2008
Mersi boku. Good idea. I'll become your regular visitor and RSS subscriber.
September 25th, 2008
We put together a Google Mashup with FBI crime data, Craigslist defense and safety classes and the Google map. Check out the application in action:
http://www.homesecurity8.com/map/Washington/Seattle.html
P.S. We would really like to know if their is other data that we can feed into this mashup or if anyone has any suggestions on how to improve it.
November 3rd, 2008
Great work and great tutorial ! Do you have any ideas, also, if you can get voice/sound using your script ?
November 7th, 2008
Can you explain a little more how to send the pictures through mail?
November 16th, 2008
Hi, everybody
December 4th, 2008
This has to be the best use for twitter I've seen yet.
December 4th, 2008
Thanks, Jay
December 24th, 2008
Hello i will be glad if you can take me step by step on how to set the security web cam up i am new to linux i just dont understand the procedure also i just cant use my webcam i am using toshiba satellite 300d i really need your help i have been using this laptop for some time now and i cant get my webcam to work also i am running ubuntume 8.10 i will be glad if you can take me through this u can send me the detail to my email as well
December 27th, 2008
Hello, Im from Brazil.
Using Lynx :
echo ’status=Motion Detected! Check Immediately’ | lynx –auth=USER:PASSWORD –dump -post_data http://twitter.com/statuses/update.xml
December 28th, 2008
Very useful resource! Thank you Shant - I've added your blog post to one of my newer blog entries.
P.S. Would motion cameras work equally well?
December 30th, 2008
I like the idea but i cant get it to work with the perl script. Do I need to edit the perl script? Where do I paste the perl script command? After track_type?
December 30th, 2008
I'm really confused on the last step. I'm a total ubuntu 8.04 noob. Help me please! thanks.
December 30th, 2008
@Richard: You need to paste the script command after "on_motion_detected" and not "track_type". Also sending you an email. Check that.
January 5th, 2009
Thats really cool, I'm going to try that out, thanks for sharing that.
February 11th, 2009
I've just finished a similar project, this time with a bit of hardware connected to a burglar alarm:
http://www.kelvinsthunderstorm.com/2009/02/twitter-burglar-alarm/
February 11th, 2009
@Kelvin: That's awesome..Keep it up..I'd be watching out your blog for more of your hacks with twitter and/or Arduino..
February 12th, 2009
Very nice twitter hack!
http://www.brackhole.com
April 1st, 2009
Here is a list of applications that do similar motion capture on PC, you should add your application there. http://www.ugolog.com/pages/25-applications-to-turn-your-webcam-into-home-security-system
Trackbacks