Fun With Webcam In Linux Fill Your Password To Invite Your Buddies - Not So Fast!!
May 14
My Sites: My Blog | My Tech Blog | Follow me on Twitter
----

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

CODE:
  1. 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:

CODE:
  1. 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:

CODE:
  1. 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:

CODE:
  1. /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.


----
If you liked this post, then you can Subscribe to my feed
Quote of the day: "Human beings may not be perfect, but a computer program with language synthesis is hardly the answer to the world's problems." - JC Denton
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • blogmarks
  • IndianPad
  • StumbleUpon
  • Technorati
  • Facebook
  • Live
  • Reddit
  • Slashdot
  • YahooMyWeb
  • e-mail

Related posts

written by Shantanu Goel \\ tags: , , , , , , , , ,

37 Responses to “Keep Tab On Home Security With A Webcam And Twitter”

  1. Amy Motta Says:

    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.

  2. John Tantalo Says:

    For some users, I think this technique might be more accurate if the notification message was "Cat Detected! Check immediately!"

  3. nerdd.net | news and opinion Says:

    Keep Tab On Home Security With A Webcam And Twitter | nerdd.net...

    \r\nWorried about someone breaking into your house in your absence? Or just need to keep a tab on wh...

  4. coolant Says:

    Hey .... second post on Lifehacker ...
    Cheers!

  5. Shantanu Goel Says:

    @Amy: Thanks... :)
    @John: Didn't get you...Do u mean, context based messages?

    @Coolant: Thanks man..

  6. Chris Radcliff Says:

    @Shantanu: I think John means that motion isn't the best criteria for an alert if you have pets moving around all day.

  7. Shantanu Goel Says:

    @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

  8. Get Twitter Notifications From a Motion-Detecting Webcam [Step By Step] · TechBlogger Says:

    [...] command line work, but it’s spelled out and explained pretty thoroughly. Photo by MShades. Keep Tab On Home Security With A Webcam And Twitter [My Technophilic [...]

  9. blu Says:

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

  10. Shantanu Goel Says:

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

  11. steven Says:

    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?

  12. Shantanu Goel Says:

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

  13. steven Says:

    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

  14. Shantanu Goel Says:

    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.

  15. steven Says:

    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.

  16. steven Says:

    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?

  17. Shantanu Goel Says:

    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.

  18. steven Says:

    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.

  19. Home Security via Twitter (Linux Only) at Twitterholics Says:

    [...] A Ubuntu user wrote a tutorial that details how to use a webcam tool to notify you via Twitter when there is any suspicious movement in your home. The notifications can also be sent to you as text messages to your mobile phone. Filed under Linux | var disqus_url = 'http://www.twitterholics.com/?p=569 '; var disqus_title = 'Home Security via Twitter (Linux Only)'; var disqus_message = 'A Ubuntu user wrote a tutorial that details how to use a webcam tool to notify you via Twitter when there is any suspicious movement in your home. The notifications can also be sent to you as text messages to your mobile phone.%0A'; View the entire comment thread. [...]

  20. Website Design Says:

    That's pretty nifty.

  21. Paul Says:

    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.

  22. Google’s New Favicon | My Technophilic Musings Says:

    [...] other news, my Twitter-Webcam integration post has bypassed my earlier lifehacked post about Remote File Access Through E-mail by more than a few [...]

  23. Sweet Hacks - Vol II | GrokCode Says:

    [...] WikiViz is a Java program that renders graphical representations of graphs containing nodes and edges. In this case, the nodes are Wikipedia category pages and the edges are links between pages. The algorithm works by first placing each node, and then iteratively moving strongly linked nodes closer together and springing weakly linked nodes farther apart. Overlapping nodes are nudged away from each other by a different proccess. WikiViz can be used on other datasets such as related books in Amazon. Home Security Via Twitter and a Webcam [...]

  24. Softsaurus.org » Blog Archive » Get Twitter Notifications From a Motion-Detecting Webcam Says:

    [...] command line work, but it’s spelled out and explained pretty thoroughly. Photo by MShades. Keep Tab On Home Security With A Webcam And Twitter [My Technophilic [...]

  25. PJ Says:

    How do you know if your computer is linux or not?

  26. USP Says:

    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.

  27. Shantanu Goel Says:

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

  28. Twitter, ça sert aussi à choper les voleurs | Korben Says:

    [...] avez envie de faire pareil ? Alors rien de plus simple, toutes les explications se trouvent ici… Moi j’aurais bien envie de l’améliorer son script [...]

  29. PJ Says:

    Yeah, I had a brain lapse for a minute. Sorry
    I know some things but I am still new to all of this.

  30. links for 2008-06-19 « Donghai Ma Says:

    [...] Keep Tab On Home Security With A Webcam And Twitter | My Technophilic Musings (tags: security twitter webcam linux surveillance hacks diy electronics) [...]

  31. Mike Says:

    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.

  32. Keep Tab On Home Security With A Webcam And Twitter | Paul M. Done Says:

    [...] room while you are away? Well, all you need is a webcam, a linux PC/laptop and a twitter account.read more | digg story Click Here - Tell the World These icons link to social bookmarking sites where [...]

  33. Linux: DIY Security System via Webcam and Twitter | Hackosis Says:

    [...] Tech.shantanugoel.com writes about how to create a do-it-yourself security system using nothing more than a Linux PC, Webcam, and a Twitter account. [...]

  34. Raseel Says:

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

  35. dpayne Says:

    Great tips! Hopefully this can be a cheap and easy way to improve home security.

  36. Digitalpedia » Blog Archive » Linux: DIY security system with webcam & Twitter Says:

    [...] Goel has an interesting post on how to turn your Linux PC/Laptop into a surveillance system using a webcam and Twitter. No [...]

  37. Links for 08/07/2008 « 8-bits of Coffee Says:

    [...] you want to keep taps on who sneaks in and borrows your lipstick while you’re gone, check out this site on how to set up your webcam to work as a security cam and take pictures and better yet sends them [...]

Leave a Reply