Rafa Juárez
Published © GPL3+

Temboo, Dropbox & Blynk - A Free Combination For Makers

Temboo is very easy to automate the IoT with Arduno YUN, in combination with Blynk and Dropbox to store pictures. All is free and easy.

BeginnerProtip4 hours2,209
Temboo, Dropbox & Blynk - A Free Combination For Makers

Things used in this project

Hardware components

Arduino Yun
Arduino Yun
×1

Software apps and online services

Temboo
Temboo
Blynk
Blynk
Arduino IDE
Arduino IDE
Linino
Python

Hand tools and fabrication machines

Mobile or tablet with Blynk app

Story

Read more

Code

Arduino sketch to take a picture using the fswebcam command to be uploaded to Dropbox

Arduino
We call fswebcam command in Linino, and we use a Python script shwon on the Adafruit tutorial called wireless-security-camera-arduino-yun.pdf
// Sketch to upload pictures to Dropbox when PUSHBUTTOM IN BLYNK is pressed
// be aware that temboo will permit till 250 calls to Temboo per calendar month in the free plan.


#include <Bridge.h>
#include <Process.h>
#include <BridgeClient.h>
#include <BridgeServer.h>
#include <BlynkSimpleYun.h>

//Blynk authorization code for the Blynk
char auth[] = "YOUR AUTHO TOKEN OF YOUR BLYNK PANEL";

// Picture process
Process ProcesoLinino;

// Filename
String filename, file_ino;

// Pines
int hacerfoto = 8; //When it is ON we take the picture
int pin13 =13; //only for diagnostics

// Path
String path = "/mnt/sda1/";   //SD card root in the YUN

// To define the variables for the LEDs on the Blynk panel
// They will be activated through the Arduino sketch and Blynk // will update their states

//****************************************************************************************************
// Meaning of the LEDs widges with:
//*********************************
// led1 will be solid when the command fswebcam is sent to 
// Linino to take the picture.

// led2 will be solid when we call the phyton script to upload // the taken picture to DropBox

// led3 will blink as an indicator of Arduino YUN is running // and there is comunication with Blynk

    WidgetLED led1(V1);     
    WidgetLED led2(V2);
    WidgetLED led3(V3); 
//****************************************************************************************************

void setup() {
  Serial.begin(9600);
  file_ino="yun_camera060317.ino";
  
  // Bridge takes about two seconds to start up
  // it can be helpful to use the on-board LED
  // as an indicator for when it has initialized  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Serial.println("Sent auth to Blynk...");
  Blynk.begin(auth);//Sent auth to Blynk...
  Serial.println("Activating Bridge to Linino.......");
  Bridge.begin();//Activating Bridge to Linino.......
  digitalWrite(13, HIGH);
  // Set pin mode
  pinMode(hacerfoto,INPUT);
  Serial.print("Fichero INO -->  ");
  Serial.println(file_ino);
  delay(3000);
}

void loop(void) 
{
 // Initialize the client library for Blynk
  Blynk.run();
  Serial.println("Blynk running....");
  digitalWrite(13, LOW);
  led3.setValue(255);
    if (digitalRead(hacerfoto) == HIGH) 
    {
                // To create filename as the retuned value of timeStamp.
                filename = "";
                Serial.print("1. To name the picture file as the timestamp  ");
                digitalWrite(13, LOW);
                ProcesoLinino.runShellCommand("date +%s");
                while(ProcesoLinino.running()); //Waiting while ProcesoLinino to get the timestamp is running
                led3.setValue(0);
                Serial.print("2.Returned code after Process completed. 0 is OK, any other number when there was a failure....   ");
                Serial.println(ProcesoLinino.exitValue());////////////////
                while (ProcesoLinino.available()>0) { //While there are values returned by the process, in this case the instance of the process returns an String with the timestamp.
                char c = ProcesoLinino.read();
                filename += c;
                } 
                filename.trim();
                Serial.println(filename);
                filename += ".png";   //Filename is composed including its extension
                
                ////INSTEAD TO UPLOAD MANY FILES WITH TIMESTAMP AS FILENAME DUE TO DELETE THEM AT DROPBOX IS DIFICULT, I OVERWRITE THE FILENAME TO A FIX NAME.
                filename = "FOTOYUN.png";
                
                // Mount the SD
                ProcesoLinino.runShellCommand("cd  /mnt/sda1");
                Serial.print("3.Returned code after request change directory where the SD card is....  ");
                Serial.println(ProcesoLinino.exitValue());////////////////// 
                led3.setValue(255);
                
                // Take picture 
                Serial.println("3.To send the comand fswebcam to Linino to take the picture , store the picture at the desired path and filenam and also adjusting its resolution");
                digitalWrite(13, HIGH);
                led1.setValue(255);
                led3.setValue(0);
                ProcesoLinino.runShellCommand("fswebcam " + path + filename + " -r 1280x720");
                while(ProcesoLinino.running()); //Waiting while ProcesoLinino to get the picture... fswebcam... is running
                digitalWrite(13, HIGH);
                Serial.print("4.Returned code after running fswebcam command is....  ");
                Serial.println(ProcesoLinino.exitValue());//////////////////////////////////////////////
                digitalWrite(13, LOW);
                led3.setValue(255);
                led1.setValue(0);
                
                // Upload to Dropbox
                led2.setValue(255);
                Serial.println("5.To upload to Dropbox, a python scrip is ran by the Linino");
                digitalWrite(13, LOW);
                ProcesoLinino.runShellCommand("python " + path + "upload_picture.py " + path + filename);
                while(ProcesoLinino.running());
                led3.setValue(0);
                Serial.println("6.Returned code after ran the python script that upload the filename to Dropbox....    ");
                Serial.println(ProcesoLinino.exitValue());//////////////////////////////////////////////
                led2.setValue(0);
                led3.setValue(255);
                Blynk.email("emailto@gmail.com",filename,"https://www.dropbox.com/home/Aplicaciones/mmc2vlcAPP1"); // An email is sent after uploading the picture to Dropbox by using Blynk.
                delay(5000);
                led3.setValue(0);
                delay(5000);
                led3.setValue(255);
                delay(5000);
                led3.setValue(0);
                delay(5000);
                led3.setValue(255); //THESE LINES ARE JUST TO CREATE THE BLYNKING EFFECT OF THE LED3 AS A WATCHDOG LED
                delay(5000);
                led3.setValue(0);
                delay(5000);
                led3.setValue(255);
                delay(5000);
                led3.setValue(0);
                delay(5000);
              
      }
        else
        {
        Serial.println("Awaiting for user to press the Blynk buttom remotelly.................");
          
          }

      led3.setValue(255);
      delay(2000);
      led3.setValue(0);
      delay(2000);        
          
            
}

Scrip file from Adafruit tutorial

Python
You need to change some parameters after Temboo and Dropbox application is created
# coding=utf-8
# Script to upload files to Dropbox

# 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")
uploadFileInputs.set_AppKey("yourAppKey")
uploadFileInputs.set_FileContents(encoded_string)
uploadFileInputs.set_Root("sandbox")

# Execute choreo
uploadFileResults = uploadFileChoreo.execute_with_results(uploadFileInputs)

Credits

Rafa Juárez

Rafa Juárez

18 projects • 39 followers
Very interested in prototyping of new ideas. 30 years experience in electronics.

Comments