Hardware Reference
In-Depth Information
4.4
Wireless Pictures Recording
What we want to achieve in this application is to take a picture whenever some motion is
detected by the PIR motion sensor. And when that happens, store this picture locally on the
SD card, and upload it to Dropbox. To do so, the code will be composed of two parts.
The first one is a Python script that will connect to Dropbox, take a picture on the SD card,
and then upload this picture to Dropbox. The reason to use Python for this part is that it is
much easier to upload files to Dropbox using Python than directly from the Arduino sketch.
The second part of the code will be the Arduino sketch itself, which will basically call the
Python script to take pictures via the Bridge library of the Yun.
Let's first code the Python script. This is the complete code for this part:
# Import correct libraries
import base64
import sys
from temboo.core.session import TembooSession
from temboo.Library.Dropbox.FilesAndMetadata import UploadFile
print str(sys.argv[1])
# Encode image
with open(str(sys.argv[1]), "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
# Declare Temboo session and Choreo to upload files
session = TembooSession('yourSession', 'yourApp', 'yourKey')
uploadFileChoreo = UploadFile(session)
# Get an InputSet object for the choreo
uploadFileInputs = uploadFileChoreo.new_input_set()
# Set inputs
uploadFileInputs.set_AppSecret("yourAppSecret")
uploadFileInputs.set_AccessToken("yourAccessToken")
uploadFileInputs.set_FileName(str(sys.argv[1]))
uploadFileInputs.set_AccessTokenSecret("yourTokenSecret")
 
Search WWH ::




Custom Search