Equipment:
- Raspberry Pi (i used a 256mb revB)
- Webcam (£5 from B&M’s)
- Powered USB hub
- WiFi adaptor (Edimax EW-7811UN)
- SD Card with Raspbian
So you have all the above? Plug the USB Hub into power, plug the webcam into the hub, put yur SD card into the Pi, feed a mini-usb from the hub to the Pi power-in. Get the WiFi up and running (i wont go into this as it was ages ago that i did my WiFi on the Pi), enable SSH (again, ages ago i enabled that, but i think it can be done through raspi-config), then you ca start with setting up the webcam!
- sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get install ssmtp
You’ll use ssmtp as a gateway for email out from the Pi. Go to gmail and ensure you have a gmail account, then edit the ssmtp.conf
- sudo nano /etc/ssmtp/ssmtp.conf
Edit these lines:
- root=YourUsername@gmail.com
- mailhub=smtp.gmail.com:465
- rewriteDomain=gmail.com
- FromLineOverride=YES
- Add these lines at the bottom of the config file:
- AuthUser=YourUsername
- AuthPass=YourPassword
- UseTLS=YES
Ctrl-x, save the changes.
- sudo apt-get install motion
motion is the camera control software. You’ll need to edit the conf file
- sudo nano /etc/motion/motion.conf
Make the following changes…
- daemon on
- v412_palette 2
- width 320
- height 240
- framerate 2
- webcam_port 8080(or whatever port you want to use)
- control_port 8081(or whatever port you want to use)
- control_localhost off
You may need to fine-tune some of the various setting to your own needs.
Now the fun stuff… Have it send you an email upon motion detection… Still in motion.conf, modify on_event_start to:
- on_event_start mail -s “WebCam Motion Detected” your@email.co.uk
you can expand on this, have it post to Facebook, using the email format. Log into Facebook and into the Mobile options, and you’ll get a unique email address that you can send an email to, which will post to your wall…
- on_event_start mail -s “Facebook Post message text from my rPi security cam” youruniquefacebookemail@m.facebook.com
Or, have it do both, combine several commands with a ‘;’ between!
- on_event_start mail -s “WebCam Motion Detected” your@email.co.uk; mail -s “Facebook Post message text from my rPi security cam” youruniquefacebookemail@m.facebook.com
What else could you do here? Use an email to text service so you can have it send you a text if you like, or post to Twitter. Use your imagination.
FTP the images to an off-site FTP server. Why? Well whats the point of having them stored locally? If the rPi gets stolen, then the images are gone!
Still in motion.conf
- On_picture_save wput -BR ftp://yourftpusername:yourftppassword@yourftpaddress %f
This will copy the files to the ftp site complete with full filename (and each image has its own date/time based image name so it wont overwrite), then it’ll check its been uploaded and delete the local file. Nice.
You can now Ctrl-x and save motion.conf, and then start it running
- sudo service motion start
If you find yourself tweaking motion.conf to fine-tune for your own needs, you’ll need to restart the motion service
- sudo service motion restart
Potential GTA hoodie caught in the act…
Check your cam – http://your.ip.address:8080
Modify settings can be done here – http://your.ip.address:8081
You might want to use port forwarding on your router and a service such as no-ip to allow you to view from outside your local network (ie. over the web)
I wanted a way to pause/resume the motion sensing, so i could leave or return and not keep sending false posts to Facebook. I was considering knocking up an iPhone app, but realised that the app would be web-based anyway so it’d be a whole lot quicker/easier just to knock up a quick web page. Obviously the controls are password protected (in motion.conf).
There’s quite a few bits and pieces you could add in, such as an alarm – using the on_event_start you could add a command to play a wav file through connected speakers. Maybe add in a relay to activate lighting? Personally, i’ve gone with seperate PIR lighting.
Would be interested to hear what modifications others have done :o)