Thursday, January 30, 2014

Make a Surveillance Motion Detected Camera with Raspberry Pi



Buy CCTV camera with motion detected feature can be very expensive. We can make it ourselves with reasonable price. One of quite popular ones is using Raspberry Pi. There are lots of article you can use to make it.

Ingredients

- Raspberry Pi model B
- SD Card, 16 GB
- Logitech C310 usb camera

You can also use Raspberry Pi model A, but you will need a Wifi dongle to connect to your network. For camera you can use more advance camera with higher resolution. Unless you really need HD quality pictures, the one I use is more than sufficient. Higher resolution you use will generate bigger file size, so you will need more space to store them in your pi.

View Captured Pictures Later

I follow this article to make for my own. In the article it even has a nice outdoor cctv housing.

Additional step that I did is to save the picture files into different folder. You can save them also to your server for you to few the pictures later. Open terminal and type:

sudo mkdir /home/pi/monitor

chgrp motion /home/pi/monitor

chmod g+rwx /home/pi/monitor

chmod R g+w /home/pi/monitor


To see the pictures from other computer, you will have to setup Samba, follow this article to set it up. Then from your computer, open the folder and view what happened during the day using any picture or video viewer.

Reason to do this is by default pictures is saved to /tmp/motion which will be automatically deleted by the OS. Some people send the pict to email automatically when the camera detected a motion, so you can received email notification with picture from your email.


Setting up automatic email

You must have a Google account to do this. The video will be save in your Google drive. From there you optionally can send to other email account. First, you need to install python:

sudo apt-get install python-pip


sudo pip install gdata


Then download uploader.py and uploader.cfg:

sudo wget http://files.mihevc.org/raspi/motion/uploader -O /etc/motion/uploader.py 

sudo wget http://files.mihevc.org/raspi/motion/uploader.cfg -O /etc/motion/uploader.cfg 

sudo chmod +x /etc/motion/uploader.py 

sudo nano /etc/motion/uploader.cfg

Complete your credentials, change the fields entry with yours:

[gmail]
# GMail account credentials
name = your_user_name
user = your_account_name
password = your_password
sender = your_email_address

# Recipient email address (could be same as from_addr)
recipient = destination_email_address

# Subject line for email
subject = Motion detected

# First line of email message
message = Video uploaded

[docs]
# Folder (or collection) in Docs where you want the videos to go
folder = motion

[options]
# Delete the local video file after the upload
delete-after-upload = true

# Send an email after the upload

send-email = true

Make sure you have created a folder named "motion". This is where the video files will be stored.

Testing if the uploader works:

python ./uploader.py /etc/motion/uploader.cfg /home/pi/monitor/*.avi

If everything is okay, then open motion.conf, add the following line at the end of the file.

on_movie_end python /etc/motion/uploader.py /etc/motion/uploader.cfg %f

Next is to run python uploader scheduler using crontab.

crontab -e


Add the following line at the end of the crontab.

* * * * * python /etc/motion/uploader.py /etc/motion/uploader.cfg /home/pi/monitor/*avi

Then reboot your Pi.

sudo shutdown -r now

Your surveillance camera is now ready to rock. You can leave your house safely and monitor your house from anywhere in the world.

4 comments:

Fnord said...

Thank you for your guide.
I had problems with Arch Linux, it was good to find you.

I have however one single problem:
The files within /home/pi/monitor have permissions that prevent the script to delete them.
Do you have any idea how I can fix that?

Fnord said...

Ok got a workaround.
Insert in uploader.py after line 116 the following:
os.chmod(video_file_path,0644)

Thanks to the allmighty Bazz!

Cornextorium said...

Hi Fnord, glad to hear you solved your problem, and thanks for the tip!

Barbara Hohensee said...

problem with watching the video from the Link:
When I open the "Something's happening" mail on an Android phone, I'm not able to watch the video directly out of the mail. When I click on the link, Android try to download some kind of .swf ...
I can watch the video when I open the Drive App on the Android phone, go the the folder and click on the video.
When I open the Email on my Mac, I can watch the video by clicking on the Link.
I think, it's kind of important to be able to watch the video when I'm not home!