'Tis the season for traveling to places in addition to celebrating the birth of the Lord Jesus. As we live in a rough neighborhood, safety of our apartment during trips always has been a concern to us. This year, we will have additional security measure in our household: webcam surveillance system! For those of you who are planning on breaking into our home, give it a second thought, better yet, repent! As you read this article, you may think we're way too paranoid or something, but I think it's kind of a fun project even if you're not paranoid about it. I had fun with it
There are 5 steps to this process. Let's begin!
Pre-requisites:
- Working webcam in Ubuntu (beyond the scope of this article; please research on Google and Ubuntuforums.org)
- Always-on Internet connection
- Remote SSH server: you can get one free sometimes, see here.
Procedures
- Install apache2, motion, and ssh
- Configure motion
- Install & Configure mutt
- Write a bash script
- When you're ready to leave the house
1. Install apache2, motion, and ssh
Really this is the easy part. In your terminal just do:sudo apt-get install ssh
sudo apt-get install motion
2. Configure motion
Using your fav. text editor (vim, mousepad, gedit, etc) replace the entire text with the text below. This configuration is what works for me and you may wish to change it by referring to this page.# Debian motion package - for basic webcam operation.
#
# You most certainly want to investigate
# /usr/share/doc/motion/examples/motion-dist.conf.gz
# for further configuration options. Also, refer to the
# motion man page and /usr/share/doc/motion/motion_guide.html
# for detailed information on configuration options.
daemon off
quiet on
# You may very well need to change this (check with 'dmesg'
# after plugging in your webcam).
videodevice /dev/video0
# Image size in pixels (valid range is camera dependent).
width 320
height 240
framerate 15
quality 100
auto_brightness off
# General threshold level and noise threshold
# level (for distinguishing between noise and motion).
threshold 4500
noise_level 32
# Initial brightness, contrast, hue (NTSC), and saturation.
# 0 = disabled (valid range 0-255).
brightness 0
contrast 0
saturation 0
hue 0
# Encode movies in real-time (install ffmpeg before enabling).
ffmpeg_cap_new off
# Codec to be used by ffmpeg for the video compression.
# Supported formats: mpeg4, msmpeg4.
ffmpeg_video_codec msmpeg4
snapshot_filename %Y%m%d%H%M%S-snapshot
# Target base directory for pictures and films (you may need
# to change this (or change its permissions) depending on
# which system user runs motion).
# DEFAULT: target_dir /var/lib/motion/snapshots
target_dir /home/XXX/XXXX
# Define a port number (e.g. 8000) to enable the mini-http server.
# 0 = disabled.
webcam_port 8000
# webcam via the mini-http server (http://hostname:port).
webcam_localhost off
webcam_motion on
webcam_quality 70
low_cpu 1
output_normal on
gap 4
on_motion_detected motion-detect
post_capture 3
3. Configure mutt
Mutt is an email server program that lets you send email from your computer via command line, which means you can easily incorporate it into a bash script (this, I argue, is the power of Linux!).I am not an expert of this program, and somebody else with a good how-to article is. So I'll do the honorable cheating thing and refer you to his how-to right here
Please note that if configuring mutt is too much or it doesn't work for you, you don't necessarily have to have it. I incorporated it into my system because I wanted my computer to email the intruder's pictures to me before they can steal my computer. Even without this emailing feature, the SSH program will transfer the pictures to another computer so you can look at them in the worst case scenario (they steal your computer).
4. Write a BASH script
This is the important part. The program motion lets you detect motion and and take pictures, but it won't do anything with those pictures. So if your computer is stolen, the pictures won't do any good. Instead, you can have your computer send the pictures to another computer and/or email them to yourself immediately.First, create a text file with a content that will be used in the email that will be sent to yourself (the location of this file is called "/home/PATH-TO-TEXT" below).
tar -cvzf /home/PATH-TO-COMPRESSED-FILE/detected-motion.tar.gz /home/PATH-TO-PICTURES-TARGET-FOLDER/*
scp /home/PATH-TO-COMPRESSED-FILE/detected-motion.tar.gz USERNAME@YOU.COM:/PATH-TO-STORE-COMPRESSED-FILE/
mutt -a /home/PATH-TO-COMPRESSED-FILE/detected-motion.tar.gz -s motion-detected YOU@YOU.COM < /home/PATH-TO-TEXT
Please note that you'll want to remove the line that starts with "mutt" if you're not using this email feature.
There are quite a few things you need to change:
- Replace /home/PATH-TO-COMPRESSED-FILE/detected-motion.tar.gz with the path you'd like to use to store the pictures compressed by tar (temporarily).
- Replace /home/PATH-TO-PICTURES-TARGET-FOLDER/* with the path you used in the motion.conf file earlier
- Replace USERNAME@YOU.COM with your user name and the address (might be a DNS name or IP address) of your remote SSH server
- Replace /PATH-TO-STORE-COMPRESSED-FILE/ with the path to the directory on your remote server where you'd like to store your compressed file
- Replace YOU@YOU.COM with your email address
- Replace /home/PATH-TO-TEXT with the path to the text file you created earlier
Additionally you may want to be able to check on your computer from remote places via SSH. To be able to do this, you need either a static IP address (very expensive to get) or a dynamic DNS address (can be free). I personally use the service from www.no-ip.com (the free version).
You also must make sure that your ISP does not block the SSH port (22). If they do, you can configure your SSH server to use another port. Also make sure that your firewall does not interfere with this system. If you wish to view the picture feed from "motion" via web browser, you may have to do some port-forwarding.
5. Before you leave
Make sure that the system you set up works (I'm sure you have, I mean you gotta test it if it's a system you set up yourself :)). Now all you have to do is do the following in the terminal and go out and have a good trip (I know it's obvious, but don't let anybody turn off your computer).Have a good trip!
References:
http://infectedproject.wordpress.com/2007/06/26/set-up-a-webcam-security-system/
Also, this may be the last post before Christmas and New Year's, so let me say:
Merry Christmas
andHappy New Year!
God bless you all and thank you for visiting our website this year. We look forward to a great year in the Lord with you
TakSuyama.com Team (well, the team is just Janet and myself)
Printer Friendly
June 11th, 2010 at 4:26 pm
Have no enough cash to buy a house? Do not worry, because it is possible to receive the loan to resolve all the problems. Hence take a college loan to buy everything you want.