Step 1: You will need
- Raspberry PI B (this project is based on B+ model)
- 5V Raspberry PI power supply
- A couple of PC speakers
- TV/Monitor with composite input and its power supply
- 3.5mm jack to RCA A/V cable
- Compatible webcam (see at: http://elinux.org/RPi_USB_Webcams)
- Three female/female jumpers
- Relay 1 channel 5V PIC ARM AVR DSP
To make something easy, my webcam is conencted directly to Raspberry PI usb port. To do this i have simply drilled the wall. Everything is connected directly to the LAN network to contain costs.
Step 2: How it works
My first need was to check who is outside my home door. To do this Raspberry PI has been programmed as follow:
at a motion detection in webcam area
- turn on monitor for 40âł
- send email with snapshot & public IP URL
- send email with timelapse video & public IP URL(*)
- sound alert
obviously, snapshot and video are chronological order stored in your gmail messages.
when my public IP changes, system sends an email with updated IP.
(*) on IOS mobile devices video file can be played with Ace Player app.
Step 3: Initial settings & packages installation
Initial settings
Create two GMAIL accounts, one for store jpeg files and one for mjpeg files.
On your RPI enable access directly to graphical interface:
$ sudo raspi-config
choose option:
Desktop Log in as user âpiâ at the graphical desktop
Then reboot.
Install sendEmail
Download sendEmail tar file:
$ wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
extract it:
$ tar -zxvf sendEmail-v1.56.tar.gz
copy to correct path:
$ sudo cp -a sendEmail-v1.56/sendEmail /usr/local/bin
make it executable
$ chmod +x /usr/local/bin/sendEmail
Install TLS support for Gmail
$ sudo apt-get install libnet-ssleay-perl libio-socket-ssl-perl
after installing, change it as follow:
$ sudo nano /usr/share/perl5/IO/Socket/SSL.pm
with CTRL-W find the line with this argument:
m{^(!?)(?:(SSL(?:v2|v3|v23|v2/3))|(TLSv1[12]?))$}i
and change it to:
m{^(!?)(?:(SSL(?:v2|v3|v23|v2/3))|(TLSv1[12]?))}i
save and exit
try to send an email with the command line:
$ sendEmail -f [email protected] -t [email protected] -u "OBJECT" -m "MESSAGE TEXT" -xu [email protected] -xp YOURPASSWORD -o tls=yes -s smtp.gmail.com:587
Install Chromium Browser
$ sudo apt-get install chromium-browser
set now Chromium browser autostart kiosk mode:
$ sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
(if you havenât NOOBS : sudo nano /etc/xdg/lxsession/LXDE/autostart)
#@lxpanel âprofile LXDE
#@pcmanfm âdesktop âprofile LXDE
#@xscreensaver -no-splash
# auto run the browser
@xset s off@xset -dpms
@xset s noblank
@chromium âkiosk âenable-kiosk-mode âenabled âtouch-events âtouch-events-ui âdisable-ipv6 âallow-file-access-from-files âdisable-java âdisable-restore-session-state âdisable-sync âdisable-translate âdisk-cache-size=1 âmedia-cache-size=1 http://localhost:YOURWEBCAMPORT
now reboot
Install MP3 PLAYER
$ sudo apt-get install mpg123
Install Motion
$ sudo apt-get install motion
modify configuration file:
$ sudo nano /etc/motion/motion.conf
Basically, iâve changed these options:
#start as
daemon
daemon on
# Rotate image
rotate 90 (my webcam is 270° rotated)
# Image width
width 640 (check your webcam resolution)
# Image height
height 480 (check your webcam resolution)
# Maximum number of frames
framerate 2
# Threshold
threshold 15000
# Picture frames must contain motion
minimum_motion_frames 2
# Specifies the number of pre-captured
pre_capture 5
# Codec to used by ffmpeg for the video compression
ffmpeg_video_codec mpeg4
# The mini-http server listens
webcam_port 8080 (selected your preferred port)
# TCP/IP port for the http server to listen on
control_port 8081 (select different port by webcam port)
# Restrict webcam connections to localhost only
webcam_localhost off
# Command to be executed when an event starts.
on_event_start mpg123 -m âgain 70 /home/pi/testsound.mp3 ;
# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
on_picture_save sendEmail -f [email protected] -t [email protected] -u âMotion detected!â -m âhttp://â`curl -s checkip.dyndns.org|sed -e âs/.*Current IP Address: //â -e âs/<.*$//â`â:8080âł -xu [email protected] -xp YOURGMAILPSSWD -o tls=yes -s smtp.gmail.com:587 -a %f
# Command to be executed when a movie file (.mpg|.avi) is created.
on_movie_start sendEmail -f [email protected] -t [email protected] -u âMotion timelapseâ -m âhttp://â`curl -s checkip.dyndns.org|sed -e âs/.*Current IP Address: //â -e âs/<.*$//â`â:8080âł -xu [email protected] -xp YOURGMAILPSSWD -o tls=yes -s smtp.gmail.com:587 -a %f
Final settings
add following lines at rc.local file:
$ sudo nano /etc/rc.local
before âexitâ add:
sudo mkdir /var/run/motion
sudo chmod a+rwxt /var/run/motion
sudo motion
sleep 60
save and exit
create now a script that check if public IP has been changed
$ nano ipchangecheck.sh
add this script:
#!/bin/bash
IPFILE=~/ipaddress
CURRENT_IP=$(curl -s checkip.dyndns.org | sed -e âs/.*Current IP Address: //â -e âs/<.*$//â)
if [ -f $IPFILE ]; then
KNOWN_IP=$(cat $IPFILE)
else
KNOWN_IP=
fi
if [ â$CURRENT_IPâ != â$KNOWN_IPâ ]; then
echo $CURRENT_IP > $IPFILE
sendEmail -f [email protected] -t [email protected] -u âyour IP is changed!â -m $CURRENT_IP -xu [email protected] -xp YOURGMAILPASSWORD -o tls=yes -s smtp.gmail.com
save and exit
$ chmod 700 ipchangecheck.sh
if you want to check every five minutes:
$ sudo nano /etc/crontab
*/5 * * * * pi bash /home/pi/ipchangecheck.sh
save and exit
For more detail: Old PC Accessories + Raspberry PI = DoorCam & surveillance Kit