HOWTO: Creating A Raspberry Spy

When I first received the Raspberry Pi my mind raced with different possibilities. I saw people creating media centers and connecting sensors to the GPIO port.  Those are very cool projects but I came up with one of my own.  My idea was to create a surveillance center.  I don’t think this is a unique idea, but it was my idea.  I was passionate about it and made it happen.  Below is a list of components and software I used for this project.

Hardware

Here’s a picture of all of the components before I connected everything.

raspberry-pi-1

Raspberry PI Model B

I picked this up from Amazon for $40.  There are places like AdaFruit that you can get it for $35, but I think the was a delay at the time so I didn’t go for the cheaper price point.  I have Amazon prime and used the free two day shipping option.



 

Logitech Quickcam Pro 9000

I had this lying around.  Most laptop have built in cameras.  I normally use it to capture movies for YouTube.  I think its available on Amazon for $70.  The quality for the price point isn’t bad.



 

Motorola USB Power Supply

I have a few Motorola phones, and I just used one of the supplies I had from an old phone.


 

 

Wifi USB Dongle

I ordered this from Amazon for $12.  It was worth it.  The dongle is pretty powerful.  My WiFi router is downstairs two floors down, and this little device has no problems sending and receiving data to it.


 

The Assembled Unit

Yes, I’m using Legos as a case.  I have a Lego wizard for a son.  He set me up with this slick enclosure in 10 minutes.

raspberry-pi-2

Software

UVCCapture

This is an open source package for capturing video.  I saw this tutorial.  It was exactly what I wanted to do.  There are many options for video capture.  You may get better mileage with a different package.

Bash

Bash is a linux shell that is my default shell on my Pi.  I have a bash script that runs every minute.  The script uses uvccapture to take a snap shot.

Source code of capture.sh:

1
2
3
4
5
6
7
8
9
#!/bin/bash
 
APP=/usr/bin/uvccapture
FILE=/var/www/snap-$(date +%s).jpg
LOG_FILE=/var/log/capture.log
 
$APP -v -B128 -C40 -S40 -x960 -y720 -o$FILE
 
cp $FILE /var/www/snap.jpg

Python

UVCCapture doesn’t always work.  There are times that UVCCapture runs and an empty image is saved.  I wrote a small python script to clean up empty images.  This isn’t a huge problem, but I use it to remove blank images before I create time lapse footage.  You can see some of the footage I captured in this post.

Source code of cleanup-cap.py:

1
2
3
4
5
6
7
8
import os
 
for root, dirs, files in os.walk('/var/www/', topdown=False):
for name in files:
f = os.path.join(root, name)
if os.path.getsize(f) == 628:
print('removing {0}'.format(f))
os.remove(f)

Disclaimer

I’m running my bash script under root’s crontab.  I did this out of convenience.  There is a better way of doing this.  However, since this is a personal pet project I kept things fast and fun.

Be Sociable, Share!