Dropbox upload of Cacti graphs and webcam photos

This is an example configuration of uploading images to Dropbox from a Raspberry PI. The images are then linked to a Google sites webpage.

Prerequisites

  • Raspberry PI running Raspbian operating system

  • A webcam connected to the Raspberry PI

  • Cacti installation

  • Dropbox account with an API key

Raspberry configuration

Create a folder for storing the images and scripts. On the Raspberry PI command line

cd /home/pi

mkdir scripts

mkdir images

Start by downloading the Dropbox uploader from Github and configuring it: https://github.com/andreafabrizi/Dropbox-Uploader

cd /home/pi/scripts

curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh

chmod 755 dropbox_uploader.sh

At this point you must have created your Dropbox API key here: https://www.dropbox.com/developers/apps

Next start the dropbox_uploader for the first time to create the config file. Enter the API key and secret and follow instructions to configure.

Note that the dropbox uploader configuration file is created in users home directory ~/.dropbox_uploader. This means that the cron task must be running as this user and cannot be added to cron.hourly without modifications.

./dropbox_uploader.sh

Shell scripts

Three scripts are created to make this work, they could be run in just one script, but this allows them to be timed differently.

Webcam Snapshot

This script takes a snapshot with the webcam using fswebcam. Start by Installing fswebcam

sudo apt-get install fswebcam

Create script using your favourite text editor in /home/pi/scripts/snapshot.sh

The script creates a logical link to the latest snapshot that is used on the Google sites website.

#!/bin/bash

DATEFOLDER=$(date +"%Y-%m-%d")

DATE=$(date +"%Y-%m-%d_%H%M")

mkdir -p /home/pi/images/$DATEFOLDER

fswebcam -r 1280x960 --jpeg 95 /home/pi/images/$DATEFOLDER/$DATE.jpg

#Make logical link to latest image

ln -f -s /home/pi/images/$DATEFOLDER/$DATE.jpg /home/pi/images/webcam.jpg

Image upload script

Create a file to export daily graphs from Cacti and upload everything to Dropbox

/home/pi/scripts/greenhouse_to_dropbox.sh

#!/bin/sh

#get temperature Cacti Graph for dropbox export

wget "http://192.168.1.2/cacti/graph_image.php?action=view&local_graph_id=102&rra_id=2" -O /home/pi/images/temperature.png

#upload temperature and latest webcam picture to dropbox

/home/pi/scripts/dropbox_uploader.sh upload /home/pi/images/temperature.png temperature.png

/home/pi/scripts/dropbox_uploader.sh upload /home/pi/images/webcam.jpg webcam.jpg

Cleanup script

This script uploads yesterdays images to a folder in Dropbox and removes them from Raspberry PI

/home/pi/scripts/cleanup.sh

#Cleanup old images and upload to Dropbox

yesterday=$(date --date="yesterday" +"%Y-%m-%d")

/home/pi/scripts/dropbox_uploader.sh -p upload /home/pi/images/$yesterday/ /imagearchive/$yesterday/

rm -rf /home/pi/images/$yesterday/

Add rights to execute the scripts

chmod 755 greenhouse_to_dropbox.sh

chmod 755 cleanup.sh

chmod 755 snapshot_10minutes.sh

Create Cron jobs for user PI

Make a cron job to upload photos every hour and take a snapshot every 10 minutes

Start crontab editor

crontab -e

Add the following lines to the end of the file

0 * * * * /home/pi/scripts/greenhouse_to_dropbox.sh

*/10 * * * * /home/pi/scripts/snapshot_10minutes.sh

* 4 * * * /home/pi/scripts/cleanup.sh

Dropbox direct link on your website

Dropbox direct link can be then done according to Dropbox instructions: https://www.dropbox.com/help/201/en

An example of this setup can be seen in action on the main page: http://greenhouse.mydigital-home.com