DIY security system - cloud upload

In a previous article, we set up a basic DIY security system, and then expanded our system to include remote cameras. We've got the front door covered, the back door covered, and the fridge covered (to catch that pesky pizza thief). So, we go off to work and someone breaks in while we're away. We come home to find a smashed in door! Taking inventory of our losses we find they've made off with the TV, the gaming console, our entire stash of Diet Mountain Dew, and uh oh, our security system Pis! The intruder's image was likely captured, but now that evidence is gone!

How can we prevent this?

The motion software allows for a custom script to be run when a motion "movie" ends. We can take advantage of this to upload our motion captures to "the cloud." This can be done in any number of ways, but in this article we will upload our captures to Dropbox.


For this project you will need at least:

  • Your original Raspberry Pi motion capture setup
  • A Dropbox account

Although we are using Dropbox for this article, the technique can be used to upload to other services. In fact, it can be used to do anything you can script.

Configuring Dropbox

The first step is to sign up for a Dropbox account if you do not already have one. If you do, simply log in.

Now we are going to use a third-party open-source script called dropbox_uploader to upload our captures to Dropbox. Let's get that installed. On your base station Pi, make a bin directory and go there:

mkdir /home/pi/bin
cd /home/pi/bin

Now download the script and set it as executable as follows (if this doesn't work, check for updated instructions the dropbox_uploader site):

curl "" -o
chmod a+x

Next, run the script once and you will see something like the following:

 This is the first time you run this script, please follow the instructions:

 1) Open the following URL in your Browser, and log in using your account:
 2) Click on "Create App", then select "Dropbox API app"
 3) Now go on with the configuration, choosing the app permissions and access restrictions to your DropBox folder
 4) Enter the "App Name" that you prefer (e.g. MyUploader15780218011922)

 Now, click on the "Create App" button.

 When your new App is successfully created, please click on the Generate button
 under the 'Generated access token' section, then copy and paste the new access token here:

 # Access token: 

The script wants us to create an "app" at Dropbox that it can write to programmatically. Let's do that:

Go to Dropbox and click "Create App". Select "Dropbox API", then "App folder" access and give your app a name. Finally, click "Create App".

Dropbox app settings

Finally, click the "Generate Token" button.

Dropbox generate token

Once your token is generated, enter it in to the script, and the script should complete.

Now let's try it out.

echo "Hi, I'm foo!" > foo.txt
./dropbox_uploader -q upload foo.txt foo.txt

Navigate to your Apps folder on Dropbox and open the folder you configured above. You should see foo.txt in it! You now have a working Dropbox upload script!

Configure motion to upload files

On your base station Pi, edit /etc/motion/motion.conf and, just above the camera configuration, add the following line:

on_movie_end /home/pi/bin/ -f /home/pi/.dropbox_uploader -q upload %f %Y-%m-%d__%H-%M-%S__%t-%v.avi

This causes motion to invoke our uploader script every time a motion capture "movie" is finished. Ready to test it? On your base station Pi:

sudo systemctl restart motion

Wave at the camera and watch your Dropbox motion app folder. Soon you should see an avi file appear! If you do not, you can get troubleshooting information from the script by modifying the above line to be:

on_movie_end /home/pi/bin/ -f /home/pi/.dropbox_uploader -q upload %f %Y-%m-%d__%H-%M-%S__%t-%v.avi > /home/pi/upload.log 2>&1

Restart motion and cause a capture. You should be able to see any output from the attempt in /home/pi/upload.log. Use the information there to troubleshoot what might have went wrong.


You now have a working motion detection system with cloud backup in case of theft of the system itself! Be mindful that you are now potentially uploading pictures of your home to a third party. So don't do anything embarrassing!