Tag Archives: dropbox

Dropbox + Motion on the Raspberry Pi

Raspbian, the recommended default operating system of the Raspberry Pi, does not come with a native Dropbox package. The hacks I saw online were all pretty sloppy, with many showing how to bounce files from your raspberry pi to another device like a desktop PC that has dropbox installed, then using that PC to sync files. I wanted Dropbox synchronization for only a single folder, and for one purpose: to collect the photos my webcam takes when using the motion software.

(Motion is a pretty cool program that can give advanced motion sensing capabilities to a number of webcams, and live stream your webcam and/or automatically record video or take pictures when motion is detected. See: http://www.lavrsen.dk/foswiki/bin/view/Motion/WebHome)

I decided to use Dropbox’s Python API to create a script that could save my security footage. I had a number of uninvited painters scheduled to come to my apartment while I was away at work and needed something that would save to a remote location. The code that follows is tailored to the motion program. Since motion can automatically execute a program or script upon writing a file (ie: saving a photo or video triggered by motion), I decided to take advantage of this and upload each file individually as opposed to running an additional script that continually monitors the filesystem for changes.

(Will make that later… check back in a week or two). Update: more important things have cropped up like building a sous vide machine!

How to do it:

Assumptions:

  • You have a dropbox account
  • You have python and motion installed
Step 1: Download droppi script files

Accessible here

Step 2: Install Dropbox SDK Python module & create new dropbox app

Install the module:

sudo pip install dropbox

Create new app:

https://www.dropbox.com/developers/apps

Click:

Create App > Dropbox API app > Files & Datastores > Yes

Name your new app whatever you like.

Step 3: Copy down newly created app key and app secret

Paste your app key and app secret into the “keys” file downloaded in droppi.zip. There should be one key per line with app key on the first line. ie:

vg6l0juiiofvlsz8
av4hukwalmn8t9o

Step 4: Run link.py to allow dropbox API access so we can upload to dropbox

python link.py

Follow the directions in the console, you will need to click the link to allow API access. You’ll also need to paste the code received into console. This will be the last key you will need to use the droppi.py script. The rest of the keys and tokens are generated automatically for you and will be inserted into the “keys” file.

You can tell if it worked by checking your dropbox account. Do you see a new folder that bears the name of your app (may be located in a new “App” folder)? Is there a “test.txt” inside of it? If so, you’re all set for step 5.

Step 5: Configure Motion

Open the motion configuration file found at /etc/motion/motion.conf (always a good idea to make a copy). If you don’t have a configuration file, I used this sample one.

Disable video

I disabled video recording on mine because the dropbox account I’m using for motion is a new account with only about 2 gb of space in it. I disabled video recording by changing

ffmpeg_cap_new

to

ffmpeg_cap_new off

Set working directory

Choose the directory on your local machine where you would like to save your pictures and/or videos. /tmp is a good option if you don’t want long term storage. Make sure your directory is writeable by user motion.

target_dir /tmp

Add droppi upload

If you are saving images, modify the following the following (use absolute path for the droppi.py file, ie: /home/pi/droppi.py, and be sure to remove the semicolon at the front of the line)

on_picture_save python droppi.py %f

If you are saving videos:

on_movie_end value

Step 6: Enjoy your dropbox enabled surveillance system!

Save the motion.conf file, start or restart the motion daemon

sudo service motion restart

Dance in front of your camera and check your dropbox!

Coming soon: Real time Dropbox folder syncing for Raspberry Pi

This motion dropbox script was a quick proof of concept hack and was made overnight because I needed it to keep an eye on these seedy painters that were coming into my apartment while I was out all day.

Hello painters!

 05-20140109084638-00 05-20140109084641-00(1) 05-20140109084503-00 05-20140109084259-00

What’s next

A python program that continually monitors a directory for changes should not be much more difficult to create. Stay tuned…