Plant Cam
Why? What?
At the moment the single.py code just takes one photo every time it is run. I am planning on running it using cron.
**PLEASE NOTE - Don't panic, I have changed all the keys and things, so I'm not leaking personal info **
Setting Up Dropbox
Sign up to Dropbox Apps https://www.dropbox.com/developers/apps
Create App
Dropbox API app
- What type of data does your app need to store on Dropbox? Files and datastores
- Can your app be limited to its own folder? Yes
- Name your app
- Create App.
You will need this information for later:
- App key
- App secret
Setting Up Raspberry Pi
Fresh Raspian install
enable camera (if you miss it the first time, just run raspi-config) - This ask you to then reboot the pi.
Make sure you are connected to the Internets. (I would SSH into your pi now)
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-pip
sudo pip install dropboxDepending on your internet connection this may take a while.
Then we want to download this github repo.:
git clone https://github.com/RZRZR/plant-cam.gitEnter the directory
cd plant_camSetting up API
We need to put in our app key and secret, so open api.py
nano api.pyReplace key and secret with your Dropbox details. It should look something like this:
app_key = '059dr5c4cpncyhe'
app_secret = 'yjz7d06x3s462t6'Run the single.py script
python single.pyAuthorising Dropbox
First time you run single.py it will ask you to authorise the app use with Dropbox. Follow the the instructions in terminal.
pi@raspberrypi ~/plant_cam $ python single.py
1. Go to: https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=099dr5c4cpncyhe
2. Click "Allow" (you might have to log in first)
3. Copy the authorization code.
Enter the authorization code here:
Once you've entered your authorisation code it will save your access_token in the access_token.py and you won't need to authorise it again. It'll look something like this:
key = 'Yk3H7pri9Z0AAAAAAAAgrb4SFdLYqEdpMOR-Vv-wSJoVSQhiO7AYm2SXsWN1Ycbk'If you want to re-authorise, if you have a new app key and secret for example. Open access_token.py in nano and remove the key string, leaving it looking like this:
key = ''Onward!
After the first time you will see:
pi@raspberrypi ~/plant_cam $ python single.py
You are authorised!
Captured img2014-06-20_10-36-25.jpg
sending img2014-06-20_10-36-25.jpg to dropbox
uploaded: img2014-06-20_10-36-25.jpgAnd it's uploaded to Dropbox! oh... but you see the time and date is all wrong? That's annoying..
Set Date and Time
sudo apt-get install ntpdateThen we want to make sure we are set to the right timezone.
sudo raspi-configSelect 4 - Internationalisation Options Select I2 - Change Timezone Select the correct place for you and you will see something like this:
Current default time zone: 'Europe/London'
Local time is now: Fri Jul 18 18:13:36 BST 2014.
Universal Time is now: Fri Jul 18 17:13:36 UTC 2014.So, let's try taking another photo.
Scheduling the script
sudo crontab -eWe are using sudo crontab because we may want to use the GPIOs in future. Add this line to run the script every 15 minutes. :
*/15 * * * * python /home/pi/plant_cam/single.py >> /home/pi/picamera-dropbox.log 2>&1Soon your SD card will fill up with images. So, add this line to delete files every day at 8pm:
0 20 * * * find /home/pi/plant_cam -mtime +24 -name 'plant*' -exec rm {} \;Save this file.
Create your log file
cd
touch picamera-dropbox.logto watch the log updating:
watch cat picamera-dropbox.logIt'll look something like this:
You are authorised!
Captured img2014-07-18_19-04-05.jpg
sending img2014-07-18_19-04-05.jpg to dropbox
uploaded: img2014-07-18_19-04-05.jpg




