Rasppi-Dropbox

Why "Dropbox"?

 * we contemplated using the M+Box but no support currently exists for non-user accounts
 * open.michigan currently possesses a Dropbox account
 * this assumes the RPI needs to be in sync with the Dropbox Folder "share_rasppi" for the Dropbox account "open.michigan@gmail.com", which populates the RPi web server content found at http://192.168.42.1/rasppi

Why was Dropbox access implemented in this fashion?

 * no Dropbox client currently exists for the RPi platform
 * criteria is to sync the RPI with changes to the Dropbox Server but DO NOT sync the Dropbox Server with changes found on the RPI (because we don't want someone altering their RPi content to punish the other RPi users)

In exploring a number of existing "tools" in the RPi world I discovered that Drop2PI supported the required criteria. (If you want to know more about all the "tools" that did not work, you know where to find me!)

Raspberry PI setup for Drop2PI
you need to install the python "setuptools" module on the RPi in order to support the Dropbox SDK. You will need to SSH (or shcmd) into the RPi and then issue the following commands mkdir python-distribute cd python-distribute curl -O http://python-distribute.org/distribute_setup.py sudo python distribute_setup.py Now install the python "pip" tool (which is used to install the Dropbox SDK and other required python modules) sudo apt-get install python-pip sudo pip install dropbox sudo pip install watchdog Download the Drop2PI from the Dropbox Server and install it on the RPi cd /home/pi wget https://www.dropbox.com/s/n8fqkebdkx4z61s/d2pi.zip unzip d2pi.zip cd d2pi change the config.py file in the /home/pi/d2pi directory to specify the correct directory to sync with the Dropbox Server: PATH_TO_WATCH = '/media/ntfs/pi/rasppi'

Create a shell script, /usr/local/bin/d2picron, to be used to automatically run this "sync" whenever the RPi is "booted" (turned on). !/bin/sh cd /home/pi/d2pi rm /home/pi/watching.log python watching.py -e &gt;&gt; /home/pi/watching.log Add the following entry, "@reboot   pi   d2picron",  to the /etc/crontab file on the RPi:
 * 1) Unlike any other crontab you don't have to run the `crontab'
 * 2) command to install the new version when you edit this file
 * 3) and files in /etc/cron.d. These files also have username fields,
 * 4) that none of the other crontabs do.

SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

@reboot pi d2picron 17 * * * * root cd / &amp;&amp; run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.monthly ) Notice the crontab entry added begins with the parameter @reboot, which cause the Drop2PI "sync" to run every time the RPi is rebooted. THis was chosen to remove worries about when, if, or how often this sync script should be run. Of course, one can change this crontab entry to suit personal desires.

The Drop2PI sync task takes about 90 minutes, where it communicates with the Dropbox Server, checking every file in the specified folder to see if it needs to be downloaded to the RPi. The more files there are in the folder, the longer Drop2PI will run.

Setup the Dropbox Server
create a Dropbox application on the Dropbox Server for your Dropbox account using a web browser:


 * https://www.dropbox.com/developers/apps
 * Be sure to specify "yes" to the "Can your app be limited to it's own private folder" question!

Now, using a "ssh" window into the RPi, run the following commands: cd /home/pi/d2pi sudo python auth.py" This will provide a URL to use in a web browser. It allows the Dropbox Server to permit the Drop2PI application on the RPi to createand access the specified "App" folder on Dropbox Server.

NOTE: Make sure you hit "Enter" to conclude running the "auth.py" script on the RPi.

Reboot the RPi

The Drop2PI script should run automatically. After the RPi is available, you can SSH to the RPi and enter the following command: ps -ef | grep d2pi If the output from this command includes: pi 2400 2390 0 14:32 ? 00:00:00 /bin/sh -c d2picron pi 2402 2400 0 14:32 ? 00:00:00 /bin/sh /usr/local/bin/d2pcron It means the Drop2PI sync is underway. Another way to check that the Drop2PI is working, is to make a change to the web content found in the "Apps/share_rasppi" on the Dropbox Server, reboot the RPi, and then check the RPi web content to verify the change has appeared after the Drop2PI task concludes.

Some things worth knowing
Note that the crontab job is run under the user "pi". If it is run under the "root" user ID, the Drop2PI task will delete the contents of the entire /media/ntfs/rasppi directory and then will download all the contents of the Dropbox "Apps/share_rasppi" to the RPi.

On the Dropbox server, I moved the contents of "rasppi" from the home directory to the "Apps/share_rasppi" folder because there was not enough available space on the Dropbox Server to simply copy the +2GB of files the Apps folder. For Drop2PI to work correctly, the files to sync'd must be in the "Apps" folder.

The reason the Drop2PI runs ~90 minutes is due to the number of individual files that exist in the "Apps/share_rasppi" folder. This doesn't inhibit the RPi from being available for other functions, as most of the time is spent in a slow chat with the Dropbox server.

Setting up other/different Dropbox folders
First, you must have a Dropbox account with enough storage space for the content. This may require the purchase of addtional space, as Dropbox currently limits free space to 2GB. Here is current instructions provided by Dropbox.

You must then create an "App" on the Dropbox server:


 * https://www.dropbox.com/developers/apps/create
 * Select "Dropbox API app"
 * Select "files and datastores"
 * Select "Yes" for the "Can your app be limited to its own, private folder?" question
 * Enter an appname that is unique
 * Select the "Create App" button

The Dropbox Server will then present you a web page filled with a variety of information. You will need the contents of the fields labelled:


 * App key
 * App secret

These values are entered in the /home/pi/d2pi/config.py file to identify which "Apps" folder is used to sync the RPi. APP_KEY    = 'xxxxxxxxxxxx' APP_SECRET = 'xxxxxxxxxxxx' ACCESS_TYPE = 'app_folder'
 * 1) -*- coding: utf-8 -*-

TOKEN_FILE = 'dropbox_token.txt'

PATH_TO_WATCH = '/folder/name/on/rasppi/to/sync'

MD5_PATH = PATH_TO_WATCH + '-md5' AUTO_SYNC_TIME = 60 * 1 MAX_DOWNLOAD_FILE_SIZE = 1024 * 100

Note: You must also specify the PATH_TO_WATCH value with the location of the folder on the RPi you wish to be in sync with the App Folder.

Now, using a "ssh" window into the RPi, run the following commands: cd /home/pi/d2pi sudo python auth.py" This will provide a URL to use in a web browser. It allows the Dropbox Server to permit the Drop2PI application on the RPi to createand access the specified "App" folder on Dropbox Server.

NOTE: Make sure you hit "Enter" to conclude running the "auth.py" script on the RPi.

Reboot the RPi

The Drop2PI script should run automatically. After the RPi is available, you can SSH to the RPi and enter the following command: ps -ef | grep d2pi If the output from this command includes: pi 2400 2390 0 14:32 ? 00:00:00 /bin/sh -c d2picron pi 2402 2400 0 14:32 ? 00:00:00 /bin/sh /usr/local/bin/d2pcron It means the Drop2PI sync is underway. Another way to check that the Drop2PI is working, is to make a change to the web content found in the Apps folder on the Dropbox Server, reboot the RPi, and then check the RPi PATH_TO_WATCH directory to verify the change has appeared after the Drop2PI task concludes.