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.
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.
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 apt-get -y install python-pip
sudo apt-get -y install python-pip
sudo pip install dropbox
Create new app:
Click:
Create App > Dropbox API app >
App folder – Access to a single folder created specifically for your app.
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
Now, unzip droppi-motion.tar.gz file downloaded
sudo tar -zxvf droppi-motion.tar.gz
sudo gunzip /tmp/droppi-motion/droppi-motion.gz
sudo gunzip /tmp/droppi-motion/link.gz
sudo gunzip /tmp/droppi-motion/keys.gz
Step 4: Run link.py to allow dropbox API access so we can upload to dropbox
vg6l0juiiofvlsz8
av4hukwalmn8t9o
Now, unzip droppi-motion.tar.gz file downloaded
sudo tar -zxvf droppi-motion.tar.gz
sudo gunzip /tmp/droppi-motion/droppi-motion.gz
sudo gunzip /tmp/droppi-motion/link.gz
sudo gunzip /tmp/droppi-motion/keys.gz
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
How do I disable or enable making mpeg files when motion is detected?
The config option ffmpeg_cap_new controls this. You need ffmpeg libraries installed for this feature. See MpegFilmsFFmpeg
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.
example :
sudo mkdir /tmp/camera
sudo chmod 777 /tmp
sudo chmod 777 /tmp/camera
target_dir /tmp/camera
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)
sudo cp /tmp/droppi-motion/droppi-motion.py /home/pi
sudo cp /tmp/droppi-motion/droppi-motion.py /home/pi
on_picture_save python
/home/pi/droppi-motion.py %f
If you are saving videos:
on_movie_end python
/home/pi/droppi-motion.py %fStep 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!
No comments:
Post a Comment