A Raspberry Pi Security Camera With Auto Dropbox Uploads

I have a couple of these Foscam cameras and they work great, but they are big and ugly. I wanted something much smaller and more discreet. I remembered that I had one of these Xbox Live cameras. This little cam is much smaller than the Foscam ones and has a nice benefit of having a looooooong USB cable. Here's how I got it working with the Raspberry Pi.

As always, the first step is to plug in the USB thing and run lsusb:

Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 006: ID 045e:0294 Microsoft Corp. 

Cool. We are in business. Let's install Motion:

sudo apt-get install motion

So far so good. Next we need a few changes to /etc/motion/motion.conf:

daemon on
width 640
height 480
framerate 4
post_capture 100
webcam_localhost off
control_localhost off

Then, from VLC on another computer (obviously): Media -> Open Network Stream and use the URL: http://192.168.1.99:8081. It's alive!

So this worked but it was a bit unstable. The camera kept turning off after a minute or two. After a little Googling, I found out I didn't have enough power going to the USB camera. So I bought one of these. Now we are in business (really this time).

Onto the Dropbox part of the puzzle. The thing to do is to create a Dropbox app here. Choose a Dropbox API app, then Files and datastores, and finally Limit app to its own, private folder.

It ends up looking like this:

More Googling led me to this Dropbox-Uploader script. I installed it and created a file called .dropbox_uploader in my $HOME directory.

APPKEY=<your app key>
APPSECRET=<your app secret>
ACCESS_LEVEL=sandbox
OAUTH_ACCESS_TOKEN=<your oauth token>
OAUTH_ACCESS_TOKEN_SECRET=<your oauth secret>

Inside /etc/crond.d/motion:

*/5 * * * *  root    find /tmp/motion/ -name '*.jpg' -mmin +5 -exec rm {} \;

Inside a screen session:

while true ; do for file in /tmp/motion/*.swf ; do /home/pi/dropbox_uploader.sh -f /home/pi/.dropbox_uploader -p upload $file ; rm $file ; done ; sleep 1800 ; done

Now, everything is uploaded to Dropbox and I can see what's happening at my house anytime from anywhere:

Oh, and how is the Raspberry Pi doing?

top - 20:24:59 up 52 days, 22 min,  1 user,  load average: 0.53, 0.37, 0.38
Tasks:  71 total,   1 running,  70 sleeping,   0 stopped,   0 zombie
%Cpu(s): 34.3 us,  1.1 sy,  0.0 ni, 61.2 id,  0.0 wa,  0.0 hi,  3.4 si,  0.0 st
KiB Mem:    448180 total,   298156 used,   150024 free,    74104 buffers
KiB Swap:   102396 total,        0 used,   102396 free,    40224 cached

  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND                                                                 
 2196 motion    20   0  107m  63m 3396 S  30.8 14.6  32312:11 motion