nazargren
Posts: 58
Joined: Mon Jan 07, 2013 11:32 pm

Security Camera That Emails Files

Sun Jul 07, 2013 9:56 pm

I have Wheezy and Motion installed correctly on my Pi. I want to set up my Pi as a security camera that detects motion, and takes snapshots every couple seconds or so that it detects motion and sends it to my GMail. A detailed tutorial would be great. Thanks!

arbuz
Posts: 12
Joined: Mon Jul 30, 2012 12:06 am
Contact: Website

Re: Security Camera That Emails Files

Mon Jul 08, 2013 12:05 am

Can't give you detailed instructions but would like to recommend software called Motion.

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Security Camera That Emails Files

Mon Jul 08, 2013 4:40 am

You can setup Motion to just email you when it detects motion...
Like this -
http://sirlagz.net/2013/02/18/how-to-au ... snapshots/
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

User avatar
Pekka
Posts: 20
Joined: Mon Nov 19, 2012 4:11 pm

Re: Security Camera That Emails Files

Tue Jul 09, 2013 8:09 am

nazargren wrote:I have Wheezy and Motion installed correctly on my Pi. I want to set up my Pi as a security camera that detects motion, and takes snapshots every couple seconds or so that it detects motion and sends it to my GMail. A detailed tutorial would be great. Thanks!
You can use imgcmp from th libjasper package. Here is the script I use (it can retrieve the image directly from UVC webcam with uvccapture or from an url with wget):

Code: Select all

#!/bin/sh

## init
version="0.1"
interval=10
waitonmotion=100
metric="mse"
threshold=400
user=$USER
password=$PASS
url=$URL
mailto=$MAILTO
mailfrom=$MAILFROM
mailsubject="Motion detected"
mailbodyfile="./mailbody"

## msg
echo "Motion detector, Version $version, (C)2012 Pekka."
echo "Started at" `date`
echo "Interval set to $interval seconds"
echo "Metric set to $metric, threshold $threshold"

## main loop
while true
do

# get image from url
#wget -nc -q --user=$user --password=$password $url -O image.jpg

# get image from uvccapture
uvccapture -x640 -y480 -oimage.jpg

comp=`imgcmp -f image.jpg -F oldimage.jpg -m $metric 2>/dev/null`
set -- $comp
if [ $2 ]; then
        echo ""
        echo $metric=$2
        if [ -e image.jpg ]; then
                compare_result=`echo "$2 > $threshold" | bc`
                if [ $compare_result -eq 1 ]; then
                        echo `date +"%d.%m.%Y, %X"`
                        echo "Threshold exceeded, sending mail"
                        #mail -a FROM:$mailfrom -s "$mailsubject" -t $mailto < "$mailbodyfile"
                        heirloom-mailx -s "$mailsubject" -a image.jpg -r "$mailfrom" "$mailto" < $mailbodyfile
                        echo "Waiting for $waitonmotion seconds..."
                        sleep $waitonmotion
                else
                        echo "Threshold not exceeded."
                fi
        fi
else
        echo "Retrieving initial images..."
fi
mv image.jpg oldimage.jpg
sleep $interval
done
It needs libjasper1, uvccapture and heirloom-mailx packages to run. Before running replace the $USER, $PASS, $URL, $MAILTO ans $MAILFROM with your data and create the file mailbody, which should contain the body of the message that will be sent on motion detection. Like this:

Code: Select all

This is to inform you that motion has just been detected on My Cam.
Go here for image: http://url/jpg/image.jpg
or here for movie: http://url/main.htm
--
Motion detector

txt3rob
Posts: 365
Joined: Sat Aug 11, 2012 3:45 pm
Contact: Website

Re: Security Camera That Emails Files

Thu Jul 11, 2013 11:45 am

it would also be worth while emailing a link for the live streaming also to show you real time what is going on
The Raspberry Pi Hell Guy - Random Ramblings to assist me and others.
http://raspberrypihell.blogspot.com
My Github - http:/www.github.com/random-robbie/
http://www.smspi.co.uk - send free uk sms via your raspberry pi from here

User avatar
Pekka
Posts: 20
Joined: Mon Nov 19, 2012 4:11 pm

Re: Security Camera That Emails Files

Thu Jul 11, 2013 12:09 pm

txt3rob wrote:it would also be worth while emailing a link for the live streaming also to show you real time what is going on
Yes. In my case a MJPEG stream is embeded in the main.html file.

Return to “Automation, sensing and robotics”