1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-18 12:54:25 +01:00

updated and added new Temboo examples

This commit is contained in:
Federico Fissore 2013-06-28 11:08:56 +02:00
parent 0d07ff9b41
commit 4ae392b0b5
9 changed files with 921 additions and 59 deletions

View File

@ -3,13 +3,16 @@
Demonstrates making a request to the Yahoo! Weather API using the Temboo Arduino Yun SDK.
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
A Temboo account and application key are necessary to run all Temboo examples.
If you don't already have one, you can register for a free Temboo account at
If you don't already have one, you can register for a free Temboo account at
http://www.temboo.com
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
to the Internet. For more tutorials on using the Temboo Library and Temboo Arduino Yun SDK, visit
http://www.temboo.com/arduino
to the Internet.
Looking for another API? We've got over 100 in our Library!
This example code is in the public domain.
*/
@ -19,7 +22,8 @@
#include <FileIO.h>
#include <HttpClient.h>
#include <Process.h>
#include "TembooAccount.h" // contains Temboo account information, as described below
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
int numRuns = 0; // execution count, so that this doesn't run forever
int maxRuns = 10; // max number of times the Yahoo WeatherByAddress Choreo should be run
@ -38,7 +42,7 @@ void loop()
if (numRuns < maxRuns) {
// print status
Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++));
Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "...");
// we need a Process object to send a Choreo request to Temboo
Process GetWeatherByAddressChoreo;
@ -80,6 +84,7 @@ void loop()
}
Serial.println("Sleeping...");
Serial.println("");
delay(30000); // sleep 30 seconds between GetWeatherByAddress calls
}
@ -96,7 +101,8 @@ void loop()
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Visit https://www.temboo.com/account to access your Temboo account credentials.
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
Keeping your account information in a separate file means you can save it once,
then just distribute the main .ino file without worrying that you forgot to delete your credentials.

View File

@ -4,6 +4,8 @@
Demonstrates retrieving the most recent Tweet from a user's home timeline
using the Temboo Arduino Yun SDK.
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
A Temboo account and application key are necessary to run all Temboo examples.
If you don't already have one, you can register for a free Temboo account at
http://www.temboo.com
@ -14,8 +16,9 @@
Substitute these values for the placeholders below.
This example assumes basic familiarity with Arduino sketches, and that your Yun
is connected to the Internet. For more tutorials on using the Temboo Library and
Temboo Arduino Yun SDK, visit http://www.temboo.com/arduino
is connected to the Internet.
Looking for social APIs? We've got Facebook, Google+, Instagram, Tumblr and more.
This example code is in the public domain.
*/
@ -25,7 +28,15 @@
#include <FileIO.h>
#include <HttpClient.h>
#include <Process.h>
#include "TembooAccount.h" // contains Temboo account information, as described below
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
const String TWITTER_ACCESS_TOKEN = "your-twitter-access-token";
const String TWITTER_ACCESS_TOKEN_SECRET = "your-twitter-access-token-secret";
const String TWITTER_CONSUMER_KEY = "your-twitter-consumer-key";
const String TWITTER_CONSUMER_SECRET = "your-twitter-consumer-secret";
int numRuns = 0; // execution count, so this sketch doesn't run forever
int maxRuns = 10; // the max number of times the Twitter HomeTimeline Choreo should run
@ -45,7 +56,7 @@ void loop()
if (numRuns < maxRuns) {
// print status
Serial.println("Running HomeTimeline - Run #" + String(numRuns++));
Serial.println("Running ReadATweet - Run #" + String(numRuns++) + "...");
// define the Process that will be used to call the "temboo" client
Process HomeTimelineChoreo;
@ -72,17 +83,15 @@ void loop()
HomeTimelineChoreo.addParameter("-i");
HomeTimelineChoreo.addParameter("Count:1"); // the max number of Tweets to return from each request
// IMPORTANT! You'll need to substitute your own Access Token, Access Token Secret,
// Consumer Secret, and Consumer Key from the Twitter dev console into the method calls
// below. (Make sure not to delete the "AccessToken:" etc prefixes!)
// add the Twitter account information
HomeTimelineChoreo.addParameter("-i");
HomeTimelineChoreo.addParameter("AccessToken:your-twitter-access-token");
HomeTimelineChoreo.addParameter("AccessToken:" + TWITTER_ACCESS_TOKEN);
HomeTimelineChoreo.addParameter("-i");
HomeTimelineChoreo.addParameter("AccessTokenSecret:your-twitter-access-token-secret");
HomeTimelineChoreo.addParameter("AccessTokenSecret:" + TWITTER_ACCESS_TOKEN_SECRET);
HomeTimelineChoreo.addParameter("-i");
HomeTimelineChoreo.addParameter("ConsumerSecret:your-twitter-consumer-secret");
HomeTimelineChoreo.addParameter("ConsumerSecret:" + TWITTER_CONSUMER_SECRET);
HomeTimelineChoreo.addParameter("-i");
HomeTimelineChoreo.addParameter("ConsumerKey:your-twitter-consumer-key");
HomeTimelineChoreo.addParameter("ConsumerKey:" + TWITTER_CONSUMER_KEY);
// next, we'll define two output filters that let us specify the
// elements of the response from Twitter that we want to receive.
@ -151,6 +160,7 @@ void loop()
}
Serial.println("Sleeping...");
Serial.println("");
delay(90000); // sleep 90 seconds between HomeTimeline calls
}
@ -167,7 +177,8 @@ void loop()
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Visit https://www.temboo.com/account to access your Temboo account credentials.
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
Keeping your account information in a separate file means you can save it once,
then just distribute the main .ino file without worrying that you forgot to delete your credentials.

View File

@ -0,0 +1,142 @@
/*
SendATweet
Demonstrates sending a tweet via a Twitter account using the Temboo Arduino Yun SDK.
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
A Temboo account and application key are necessary to run all Temboo examples.
If you don't already have one, you can register for a free Temboo account at
http://www.temboo.com
In order to run this sketch, you'll need to register an application using
the Twitter dev console at https://dev.twitter.com. After creating the
app, you'll find OAuth credentials for that application under the "OAuth Tool" tab.
Substitute these values for the placeholders below.
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
to the Internet.
Looking for social APIs? We've got Facebook, Google+, Instagram, Tumblr and more.
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Console.h>
#include <FileIO.h>
#include <HttpClient.h>
#include <Process.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
const String TWITTER_ACCESS_TOKEN = "your-twitter-access-token";
const String TWITTER_ACCESS_TOKEN_SECRET = "your-twitter-access-token-secret";
const String TWITTER_CONSUMER_KEY = "your-twitter-consumer-key";
const String TWITTER_CONSUMER_SECRET = "your-twitter-consumer-secret";
int numRuns = 1; // execution count, so this sketch doesn't run forever
int maxRuns = 10; // the max number of times the Twitter HomeTimeline Choreo should run
void setup() {
Serial.begin(9600);
// for debugging, wait until a serial console is connected
delay(4000);
while(!Serial);
Bridge.begin();
}
void loop()
{
// only try to send the tweet if we haven't already sent it successfully
if (numRuns <= maxRuns) {
Serial.println("Running SendATweet - Run #" + String(numRuns++) + "...");
// we need a Process object to send a Choreo request to Temboo
Process StatusesUpdateChoreo;
// invoke the Temboo client
StatusesUpdateChoreo.begin("temboo");
// set Temboo account credentials
StatusesUpdateChoreo.addParameter("-a");
StatusesUpdateChoreo.addParameter(TEMBOO_ACCOUNT);
StatusesUpdateChoreo.addParameter("-u");
StatusesUpdateChoreo.addParameter(TEMBOO_APP_KEY_NAME);
StatusesUpdateChoreo.addParameter("-p");
StatusesUpdateChoreo.addParameter(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Twitter > Tweets > StatusesUpdate)
StatusesUpdateChoreo.addParameter("-c");
StatusesUpdateChoreo.addParameter("/Library/Twitter/Tweets/StatusesUpdate");
// set the required choreo inputs
// see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/
// for complete details about the inputs for this Choreo
// add the Twitter account information
StatusesUpdateChoreo.addParameter("-i");
StatusesUpdateChoreo.addParameter("AccessToken:" + TWITTER_ACCESS_TOKEN);
StatusesUpdateChoreo.addParameter("-i");
StatusesUpdateChoreo.addParameter("AccessTokenSecret:" + TWITTER_ACCESS_TOKEN_SECRET);
StatusesUpdateChoreo.addParameter("-i");
StatusesUpdateChoreo.addParameter("ConsumerSecret:" + TWITTER_CONSUMER_SECRET);
StatusesUpdateChoreo.addParameter("-i");
StatusesUpdateChoreo.addParameter("ConsumerKey:" + TWITTER_CONSUMER_KEY);
String tweet("My Arduino Yun has been running for " + String(millis()) + " milliseconds.");
StatusesUpdateChoreo.addParameter("-i");
StatusesUpdateChoreo.addParameter("StatusUpdate:" + tweet);
// tell the Process to run and wait for the results. The
// return code (rc) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int rc = StatusesUpdateChoreo.run();
// a return code of zero (0) means everything worked
if (rc == 0) {
Serial.println("Success! Tweet sent!");
} else {
// a non-zero return code means there was an error
// read and print the error message
while (StatusesUpdateChoreo.available()) {
Serial.print((char)StatusesUpdateChoreo.read());
}
}
StatusesUpdateChoreo.close();
// do nothing for the next 90 seconds
Serial.println("Sleeping...");
delay(90000);
}
}
/*
IMPORTANT NOTE: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You need to create this file. To do so, make a new tab in Arduino, call it TembooAccount.h, and
include the following variables and constants:
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
Keeping your account information in a separate file means you can save it once,
then just distribute the main .ino file without worrying that you forgot to delete your credentials.
*/

View File

@ -1,8 +1,9 @@
/*
SendAnEmail
Demonstrates sending an email via a Google Gmail account
using the Temboo Arduino Yun SDK.
Demonstrates sending an email via a Google Gmail account using the Temboo Arduino Yun SDK.
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
A Temboo account and application key are necessary to run all Temboo examples.
If you don't already have one, you can register for a free Temboo account at
@ -13,8 +14,9 @@
to log into your Gmail account: substitute the placeholders below for these values.
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
to the Internet. For more tutorials on using the Temboo Library and Temboo Arduino Yun SDK, visit
http://www.temboo.com/arduino
to the Internet.
Looking for another API? We've got over 100 in our Library!
This example code is in the public domain.
*/
@ -24,7 +26,19 @@
#include <FileIO.h>
#include <HttpClient.h>
#include <Process.h>
#include "TembooAccount.h" // contains Temboo account information, as described below
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// your Gmail address, eg "bob.smith@gmail.com"
const String GMAIL_USER_NAME = "xxxxxxxxxx";
// your Gmail password
const String GMAIL_PASSWORD = "xxxxxxxxxx";
// the email address you want to send the email to, eg "jane.doe@temboo.com"
const String TO_EMAIL_ADDRESS = "xxxxxxxxxx";
boolean success = false; // a flag to indicate whether we've sent the email yet or not
@ -44,7 +58,7 @@ void loop()
// only try to send the email if we haven't already sent it successfully
if (!success) {
Serial.println("Running SendEmail ...");
Serial.println("Running SendAnEmail...");
// we need a Process object to send a Choreo request to Temboo
Process SendEmailChoreo;
@ -69,14 +83,16 @@ void loop()
// for complete details about the inputs for this Choreo
// the first input is a your Gmail user name.
// NOTE: substitute your own value, retaining the "Username:" prefix.
SendEmailChoreo.addParameter("-i");
SendEmailChoreo.addParameter("Username:your-gmail-username");
SendEmailChoreo.addParameter("Username:" + GMAIL_USER_NAME);
// next is your Gmail password.
// NOTE: substitute your own value, retaining the "Password:" prefix
SendEmailChoreo.addParameter("-i");
SendEmailChoreo.addParameter("Password:your-gmail-password");
SendEmailChoreo.addParameter("Password:" + GMAIL_PASSWORD);
// who to send the email to
SendEmailChoreo.addParameter("-i");
SendEmailChoreo.addParameter("ToAddress:" + TO_EMAIL_ADDRESS);
// then a subject line
SendEmailChoreo.addParameter("-i");
@ -86,16 +102,6 @@ void loop()
SendEmailChoreo.addParameter("-i");
SendEmailChoreo.addParameter("MessageBody:Hey! The greenhouse is too cold!");
// next is the email address of who the email is from.
// NOTE: substitute your Gmail address, retaining the "FromAddress:" prefix.
SendEmailChoreo.addParameter("-i");
SendEmailChoreo.addParameter("FromAddress:your-gmail-email-address");
// who to send the email to
// NOTE: substitute your desired recipient, retaining the "ToAddress:" prefix
SendEmailChoreo.addParameter("-i");
SendEmailChoreo.addParameter("ToAddress:recipient-email-address");
// tell the Process to run and wait for the results. The
// return code (rc) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
@ -132,11 +138,10 @@ void loop()
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Visit https://www.temboo.com/account to access your Temboo account credentials.
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
Keeping your account information in a separate file means you can save it once,
then just distribute the main .ino file without worrying that you forgot to delete your credentials.
(Be sure to delete this comment after creating your TembooAccount.h file!)
*/

View File

@ -0,0 +1,160 @@
/*
SendAnSMS
Demonstrates sending an SMS via a Twilio account using the Temboo Arduino Yun SDK.
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
A Temboo account and application key are necessary to run all Temboo examples.
If you don't already have one, you can register for a free Temboo account at
http://www.temboo.com
Since this sketch uses Twilio to send the SMS, you'll also need a valid
Twilio account. You can create one for free at https://www.twilio.com.
The sketch needs your Twilio phone number, along with
the Account SID and Auth Token you get when you register with Twilio.
Make sure to use the Account SID and Auth Token from your Twilio Dashboard
(not your test credentials from the Dev Tools panel).
Also note that if you're using a free Twilio account, you'll need to verify
the phone number to which messages are being sent by going to twilio.com and following
the instructions under the "Numbers > Verified Caller IDs" tab (this restriction
doesn't apply if you have a paid Twilio account).
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
to the Internet.
Looking for another API? We've got over 100 in our Library!
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Console.h>
#include <FileIO.h>
#include <HttpClient.h>
#include <Process.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// the Account SID from your Twilio account
const String TWILIO_ACCOUNT_SID = "xxxxxxxxxx";
// the Auth Token from your Twilio account
const String TWILIO_AUTH_TOKEN = "xxxxxxxxxx";
// your Twilio phone number, e.g., "+1 555-222-1212"
const String TWILIO_NUMBER = "xxxxxxxxxx";
// the number to which the SMS should be sent, e.g., "+1 555-222-1212"
const String RECIPIENT_NUMBER = "xxxxxxxxxx";
boolean success = false; // a flag to indicate whether we've sent the SMS yet or not
void setup() {
Serial.begin(9600);
// for debugging, wait until a serial console is connected
delay(4000);
while(!Serial);
Bridge.begin();
}
void loop()
{
// only try to send the SMS if we haven't already sent it successfully
if (!success) {
Serial.println("Running SendAnSMS...");
// we need a Process object to send a Choreo request to Temboo
Process SendSMSChoreo;
// invoke the Temboo client
SendSMSChoreo.begin("temboo");
// set Temboo account credentials
SendSMSChoreo.addParameter("-a");
SendSMSChoreo.addParameter(TEMBOO_ACCOUNT);
SendSMSChoreo.addParameter("-u");
SendSMSChoreo.addParameter(TEMBOO_APP_KEY_NAME);
SendSMSChoreo.addParameter("-p");
SendSMSChoreo.addParameter(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Twilio > SMSMessages > SendSMS)
SendSMSChoreo.addParameter("-c");
SendSMSChoreo.addParameter("/Library/Twilio/SMSMessages/SendSMS");
// set the required choreo inputs
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/
// for complete details about the inputs for this Choreo
// the first input is a your AccountSID
SendSMSChoreo.addParameter("-i");
SendSMSChoreo.addParameter("AccountSID:" + TWILIO_ACCOUNT_SID);
// next is your Auth Token
SendSMSChoreo.addParameter("-i");
SendSMSChoreo.addParameter("AuthToken:" + TWILIO_AUTH_TOKEN);
// next is your Twilio phone number
SendSMSChoreo.addParameter("-i");
SendSMSChoreo.addParameter("From:" + TWILIO_NUMBER);
// next, what number to send the SMS to
SendSMSChoreo.addParameter("-i");
SendSMSChoreo.addParameter("To:" + RECIPIENT_NUMBER);
// finally, the text of the message to send
SendSMSChoreo.addParameter("-i");
SendSMSChoreo.addParameter("Body:Hey, there! This is a message from your Arduino Yun!");
// tell the Process to run and wait for the results. The
// return code (rc) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int rc = SendSMSChoreo.run();
// a return code of zero (0) means everything worked
if (rc == 0) {
Serial.println("Success! SMS sent!");
success = true;
} else {
// a non-zero return code means there was an error
// read and print the error message
while (SendSMSChoreo.available()) {
Serial.print((char)SendSMSChoreo.read());
}
}
SendSMSChoreo.close();
// do nothing for the next 60 seconds
Serial.println("Sleeping...");
delay(60000);
}
}
/*
IMPORTANT NOTE: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You need to create this file. To do so, make a new tab in Arduino, call it TembooAccount.h, and
include the following variables and constants:
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
Keeping your account information in a separate file means you can save it once,
then just distribute the main .ino file without worrying that you forgot to delete your credentials.
*/

View File

@ -1,26 +1,37 @@
/*
SendDataToGoogleSpreadsheet
Demonstrates appending a row of data to a Google spreadsheet
from the Arduino Yun using the Temboo Arduino Yun SDK.
Demonstrates appending a row of data to a Google spreadsheet from the Arduino Yun
using the Temboo Arduino Yun SDK.
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
A Temboo account and application key are necessary to run all Temboo examples.
If you don't already have one, you can register for a free Temboo account at
http://www.temboo.com
This example assumes basic familiarity with Arduino sketches, and that your
Yun is connected to the Internet. For more tutorials on using the Temboo Library
and Temboo Arduino Yun SDK, visit http://www.temboo.com/arduino
Since this sketch uses a Google spreadsheet, you'll also need a
Google account: substitute the placeholders below for your Google account values.
This example assumes basic familiarity with Arduino sketches, and that your
Yun is connected to the Internet.
The columns in your spreadsheet must have labels for the Choreo to
work properly. It doesn't matter what the column labels actually are,
but there must be text in the first row of each column. This example
assumes there are two columns. The first column is the time (in milliseconds)
that the row was appended, and the second column is a sensor value
(simulated in this example via a random number).
(simulated in this example via a random number). In other words, your spreadsheet
should look like:
Time | Sensor Value |
------+-----------------
| |
NOTE that the first time you run this sketch, you may receive a warning from
Google, prompting you to authorize access from a 3rd party system.
Looking for another API? We've got over 100 in our Library!
This example code is in the public domain.
@ -31,7 +42,17 @@
#include <FileIO.h>
#include <HttpClient.h>
#include <Process.h>
#include "TembooAccount.h" // contains Temboo account information, as described below
#include "TembooAccount.h" // contains Temboo account information,
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
const String GOOGLE_USERNAME = "your-google-username";
const String GOOGLE_PASSWORD = "your-google-password";
// the title of the spreadsheet you want to send data to
const String SPREADSHEET_TITLE = "your-spreadsheet-title";
const unsigned long RUN_INTERVAL_MILLIS = 60000; // how often to run the Choreo (in milliseconds)
@ -94,19 +115,17 @@ void loop()
// for complete details about the inputs for this Choreo
// your Google username (usually your email address)
// NOTE: substitute your own value, retaining the "Username:" prefix.
AppendRowChoreo.addParameter("-i");
AppendRowChoreo.addParameter("Username:your-google-username");
AppendRowChoreo.addParameter("Username:" + GOOGLE_USERNAME);
// your Google account password
// NOTE: substitute your own value, retaining the "Password:" prefix.
AppendRowChoreo.addParameter("-i");
AppendRowChoreo.addParameter("Password:your-google-password");
AppendRowChoreo.addParameter("Password:" + GOOGLE_PASSWORD);
// the title of the spreadsheet you want to append to
// NOTE: substitute your own value, retaining the "SpreadsheetTitle:" prefix.
AppendRowChoreo.addParameter("-i");
AppendRowChoreo.addParameter("SpreadsheetTitle:your-spreadsheet-title");
AppendRowChoreo.addParameter("SpreadsheetTitle:" + SPREADSHEET_TITLE);
// convert the time and sensor values to a comma separated string
String rowData(now);
@ -124,6 +143,7 @@ void loop()
// return code of zero (0) means success
if (rc == 0) {
Serial.println("Success! Appended " + rowData);
Serial.println("");
} else {
// return code of anything other than zero means failure
// read and display any error messages
@ -155,11 +175,10 @@ unsigned long getSensorValue() {
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Visit https://www.temboo.com/account to access your Temboo account credentials.
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
Keeping your account information in a separate file means you can save it once,
then just distribute the main .ino file without worrying that you forgot to delete your credentials.
(Be sure to delete this comment after creating your TembooAccount.h file!)
*/

View File

@ -0,0 +1,174 @@
/*
ToxicFacilitiesSearch
Demonstrates making a request to the Envirofacts API using the Temboo Arduino Yun SDK.
This example retrieves the names and addresses of EPA-regulated facilities in the
Toxins Release Inventory (TRI) database within a given zip code.
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
A Temboo account and application key are necessary to run all Temboo examples.
If you don't already have one, you can register for a free Temboo account at
http://www.temboo.com
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
to the Internet.
Looking for another API? We've got over 100 in our Library!
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Console.h>
#include <FileIO.h>
#include <HttpClient.h>
#include <Process.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
// the zip code to search
const String US_ZIP_CODE = "11215";
int numRuns = 1; // execution count, so that this doesn't run forever
int maxRuns = 10; // max number of times the Envirofacts FacilitiesSearch Choreo should be run
void setup() {
Serial.begin(9600);
// for debugging, wait until a serial console is connected
delay(4000);
while(!Serial);
Bridge.begin();
}
void loop()
{
// while we haven't reached the max number of runs...
if (numRuns <= maxRuns) {
// print status
Serial.println("Running ToxicFacilitiesSearch - Run #" + String(numRuns++) + "...");
// we need a Process object to send a Choreo request to Temboo
Process FacilitiesSearchByZipChoreo;
// invoke the Temboo client
FacilitiesSearchByZipChoreo.begin("temboo");
// set Temboo account credentials
FacilitiesSearchByZipChoreo.addParameter("-a");
FacilitiesSearchByZipChoreo.addParameter(TEMBOO_ACCOUNT);
FacilitiesSearchByZipChoreo.addParameter("-u");
FacilitiesSearchByZipChoreo.addParameter(TEMBOO_APP_KEY_NAME);
FacilitiesSearchByZipChoreo.addParameter("-p");
FacilitiesSearchByZipChoreo.addParameter(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (EnviroFacts > Toxins > FacilitiesSearchByZip)
FacilitiesSearchByZipChoreo.addParameter("-c");
FacilitiesSearchByZipChoreo.addParameter("/Library/EnviroFacts/Toxins/FacilitiesSearchByZip");
// set choreo inputs; in this case, the US zip code for which to retrieve toxin release data
// the Temboo client provides standardized calls to 100+ cloud APIs
FacilitiesSearchByZipChoreo.addParameter("-i");
FacilitiesSearchByZipChoreo.addParameter("Zip:" + US_ZIP_CODE);
// specify two output filters, to help simplify the Envirofacts API results.
// see the tutorials on using Temboo SDK output filters at http://www.temboo.com/arduino
FacilitiesSearchByZipChoreo.addParameter("-o");
FacilitiesSearchByZipChoreo.addParameter("fac:FACILITY_NAME:Response");
FacilitiesSearchByZipChoreo.addParameter("-o");
FacilitiesSearchByZipChoreo.addParameter("addr:STREET_ADDRESS:Response");
// run the choreo
FacilitiesSearchByZipChoreo.run();
String facs;
String addrs;
// when the choreo results are available, process them.
// the output filters we specified will return comma delimited
// lists containing the name and street address of the facilities
// located in the specified zip code.
while(FacilitiesSearchByZipChoreo.available()) {
String name = FacilitiesSearchByZipChoreo.readStringUntil('\x1F');
name.trim();
String data = FacilitiesSearchByZipChoreo.readStringUntil('\x1E');
data.trim();
if (name == "fac") {
facs = data;
} else if (name == "addr") {
addrs = data;
}
}
FacilitiesSearchByZipChoreo.close();
// parse the comma delimited lists of facilities to join the
// name with the address and print it to the serial monitor
if (facs.length() > 0) {
int i = -1;
int fstart = 0;
int astart = 0;
String f;
String a;
do {
i = facs.indexOf(',', fstart);
if (i >= 0) {
f = facs.substring(fstart, i);
fstart = i + 1;
}
i = addrs.indexOf(',', astart);
if (i >= 0) {
a = addrs.substring(astart, i);
astart = i + 1;
}
if (i >= 0) {
printResult(f, a);
}
}while (i >= 0);
f = facs.substring(fstart);
a = addrs.substring(astart);
printResult(f, a);
} else {
Serial.println("No facilities found in zip code " + US_ZIP_CODE);
}
}
Serial.println("Sleeping...");
Serial.println("");
delay(30000); // sleep 30 seconds between calls
}
// a simple utility function, to output the facility name and address in the serial monitor.
void printResult(String fac, String addr) {
Serial.print(fac);
Serial.print(" - ");
Serial.println(addr);
}
/*
IMPORTANT NOTE: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You need to create this file. To do so, make a new tab in Arduino, call it TembooAccount.h, and
include the following variables and constants:
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
Keeping your account information in a separate file means you can save it once,
then just distribute the main .ino file without worrying that you forgot to delete your credentials.
*/

View File

@ -0,0 +1,133 @@
/*
UpdateFacebookStatus
Demonstrates sending a Facebook status update using the Temboo Arduino Yun SDK.
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
A Temboo account and application key are necessary to run all Temboo examples.
If you don't already have one, you can register for a free Temboo account at
http://www.temboo.com
In order to run this sketch, you'll need to register an application using
the Facebook dev console at https://developers.facebook.com/apps. After creating
the app, log in to Temboo and visit https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/
to use our OAuth Wizard (or OAuth Choreos) to obtain a Facebook access token.
Substitute your access token for the placeholder value of FACEBOOK_ACCESS_TOKEN below.
This example assumes basic familiarity with Arduino sketches, and that your Yun
is connected to the Internet.
Looking for social APIs? We've got Twitter, Google+, Instagram, Tumblr and more.
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Console.h>
#include <FileIO.h>
#include <HttpClient.h>
#include <Process.h>
#include "TembooAccount.h" // contains Temboo account information,
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// the Facebook Access Token, which can be obtained using the Temboo OAuth Wizard or Choreos
const String FACEBOOK_ACCESS_TOKEN = "xxxxxxxxxx";
int numRuns = 0; // execution count, so this sketch doesn't run forever
int maxRuns = 10; // the max number of times the Facebook SetStatus Choreo should run
void setup() {
Serial.begin(9600);
// For debugging, wait until a serial console is connected.
delay(4000);
while(!Serial);
Bridge.begin();
}
void loop() {
// while we haven't reached the max number of runs...
if (numRuns < maxRuns) {
// print status
Serial.println("Running UpdateFacebookStatus - Run #" + String(numRuns++) + "...");
// Define the status message we want to post on Facebook; since Facebook
// doesn't allow duplicate status messages, we'll include a changing value.
String statusMsg = "My Arduino Yun has been running for " + String(millis()) + " milliseconds!";
// define the Process that will be used to call the "temboo" client
Process SetStatusChoreo;
// invoke the Temboo client
SetStatusChoreo.begin("temboo");
// set Temboo account credentials
SetStatusChoreo.addParameter("-a");
SetStatusChoreo.addParameter(TEMBOO_ACCOUNT);
SetStatusChoreo.addParameter("-u");
SetStatusChoreo.addParameter(TEMBOO_APP_KEY_NAME);
SetStatusChoreo.addParameter("-p");
SetStatusChoreo.addParameter(TEMBOO_APP_KEY);
// tell the Temboo client which Choreo to run (Facebook > Publishing > SetStatus)
SetStatusChoreo.addParameter("-c");
SetStatusChoreo.addParameter("/Library/Facebook/Publishing/SetStatus");
// set the required choreo inputs
// see https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/
// for complete details about the inputs for this Choreo
SetStatusChoreo.addParameter("-i");
SetStatusChoreo.addParameter("AccessToken:" + FACEBOOK_ACCESS_TOKEN);
SetStatusChoreo.addParameter("-i");
SetStatusChoreo.addParameter("Message:" + statusMsg);
// tell the Process to run and wait for the results. The
// return code (rc) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int rc = SetStatusChoreo.run();
// print the response code and API response.
Serial.println("Resonse code: " + String(rc));
// note that in this case, we're just printing the raw response from Facebook.
// see the examples on using Temboo SDK output filters at http://www.temboo.com/arduino
// for information on how to filter this data
while(SetStatusChoreo.available()) {
Serial.print((char)SetStatusChoreo.read());
}
SetStatusChoreo.close();
}
Serial.println("Sleeping...");
Serial.println("");
delay(30000); // sleep 30 seconds between SetStatus calls
}
/*
IMPORTANT NOTE: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You need to create this file. To do so, make a new tab in Arduino, call it TembooAccount.h, and
include the following variables and constants:
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
Keeping your account information in a separate file means you can save it once,
then just distribute the main .ino file without worrying that you forgot to delete your credentials.
*/

View File

@ -0,0 +1,212 @@
/*
UploadToDropbox
Demonstrates uploading a file to Dropbox using the Temboo Arduino Yun SDK.
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
A Temboo account and application key are necessary to run all Temboo examples.
If you don't already have one, you can register for a free Temboo account at
http://www.temboo.com
You'll also need a valid Dropbox account, and OAuth credentials for Dropbox. To
obtain OAuth credentials for Dropbox, you'll need to register a Dropbox app at
https://www.dropbox.com/developers/apps and then follow the instructions at
https://www.temboo.com/library/Library/Dropbox/OAuth/ to run the Initialize and Finalize
OAuth Choreos to complete the OAuth handshake and retrieve your Access Token information.
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
to the Internet.
Looking for another API? We've got over 100 in our Library!
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Console.h>
#include <FileIO.h>
#include <HttpClient.h>
#include <Process.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// your Dropbox app key, available on the Dropbox developer console after registering an app
const String DROPBOX_APP_KEY = "xxxxxxxxxx";
// your Dropbox app secret, available on the Dropbox developer console after registering an app
const String DROPBOX_APP_SECRET = "xxxxxxxxxx";
// your Dropbox access token, which is returned by the FinalizeOAuth Choreo
const String DROPBOX_ACCESS_TOKEN = "xxxxxxxxxx";
// your Dropbox access token secret, which is returned by the FinalizeOAuth Choreo
const String DROPBOX_ACCESS_TOKEN_SECRET = "xxxxxxxxxx";
boolean success = false; // a flag to indicate whether we've uploaded the file yet
void setup() {
Serial.begin(9600);
// For debugging, wait until a serial console is connected.
delay(4000);
while(!Serial);
Bridge.begin();
}
void loop()
{
// only try to upload the file if we haven't already done so
if (!success) {
Serial.println("Base64 encoding data to upload...");
// base64 encode the data to upload
String base64EncodedData = base64Encode("Hello, Arduino!");
Serial.println("Uploading data to Dropbox...");
// we need a Process object to send a Choreo request to Temboo
Process UploadFileChoreo;
// invoke the Temboo client
UploadFileChoreo.begin("temboo");
// set Temboo account credentials
UploadFileChoreo.addParameter("-a");
UploadFileChoreo.addParameter(TEMBOO_ACCOUNT);
UploadFileChoreo.addParameter("-u");
UploadFileChoreo.addParameter(TEMBOO_APP_KEY_NAME);
UploadFileChoreo.addParameter("-p");
UploadFileChoreo.addParameter(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Dropbox > FilesAndMetadata > UploadFile)
UploadFileChoreo.addParameter("-c");
UploadFileChoreo.addParameter("/Library/Dropbox/FilesAndMetadata/UploadFile");
// set the required choreo inputs
// see https://www.temboo.com/library/Library/Dropbox/FilesAndMetadata/UploadFile/
// for complete details about the inputs for this Choreo
// first specify the name of the file to create/update on Dropbox
UploadFileChoreo.addParameter("-i");
UploadFileChoreo.addParameter("FileName:ArduinoTest.txt");
// next, the root folder on Dropbox relative to which the file path is specified.
// unless you're using an in-production Dropbox app, this should be left as "sandbox"
UploadFileChoreo.addParameter("-i");
UploadFileChoreo.addParameter("Root:sandbox");
// next, the Base64 encoded file data to upload
UploadFileChoreo.addParameter("-i");
UploadFileChoreo.addParameter("FileContents:" + base64EncodedData);
// finally, the Dropbox OAuth credentials defined above
UploadFileChoreo.addParameter("-i");
UploadFileChoreo.addParameter("AppSecret:" + DROPBOX_APP_SECRET);
UploadFileChoreo.addParameter("-i");
UploadFileChoreo.addParameter("AccessToken:" + DROPBOX_ACCESS_TOKEN);
UploadFileChoreo.addParameter("-i");
UploadFileChoreo.addParameter("AccessTokenSecret:" + DROPBOX_ACCESS_TOKEN_SECRET);
UploadFileChoreo.addParameter("-i");
UploadFileChoreo.addParameter("AppKey:" + DROPBOX_APP_KEY);
// tell the Process to run and wait for the results. The
// return code (rc) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int rc = UploadFileChoreo.run();
// a return code of zero (0) means everything worked
if (rc == 0) {
Serial.println("Success! File uploaded!");
success = true;
} else {
// a non-zero return code means there was an error
Serial.println("Uh-oh! Something went wrong!");
}
// print out the full response to the serial monitor in all
// cases, just for debugging
while (UploadFileChoreo.available()) {
Serial.print((char)UploadFileChoreo.read());
}
UploadFileChoreo.close();
Serial.println("Sleeping...");
}
delay(30000); // sleep 30 seconds between upload attempts
}
/*
A utility function to Base64 encode the specified string
by calling a Temboo Utilities Choreo.
*/
String base64Encode(String toEncode) {
// we need a Process object to send a Choreo request to Temboo
Process Base64EncodeChoreo;
// invoke the Temboo client
Base64EncodeChoreo.begin("temboo");
// set Temboo account credentials
Base64EncodeChoreo.addParameter("-a");
Base64EncodeChoreo.addParameter(TEMBOO_ACCOUNT);
Base64EncodeChoreo.addParameter("-u");
Base64EncodeChoreo.addParameter(TEMBOO_APP_KEY_NAME);
Base64EncodeChoreo.addParameter("-p");
Base64EncodeChoreo.addParameter(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode)
Base64EncodeChoreo.addParameter("-c");
Base64EncodeChoreo.addParameter("/Library/Utilities/Encoding/Base64Encode");
// set choreo inputs
Base64EncodeChoreo.addParameter("-i");
Base64EncodeChoreo.addParameter("Text:" + toEncode);
// run the choreo
Base64EncodeChoreo.run();
// read in the choreo results, and return the "Base64EncodedText" output value.
// see http://www.temboo.com/arduino for more details on using choreo outputs.
while(Base64EncodeChoreo.available()) {
// read the name of the output item
String name = Base64EncodeChoreo.readStringUntil('\x1F');
name.trim();
// read the value of the output item
String data = Base64EncodeChoreo.readStringUntil('\x1E');
data.trim();
if(name == "Base64EncodedText") {
return data;
}
}
}
/*
IMPORTANT NOTE About TembooAccount.h:
TembooAccount.h is not included with this example because it contains your account information.
You need to create it for your own version of this application. To do so, make
a new tab in Arduino, call it TembooAccount.h, and include the following variables and constants:
#define TEMBOO_ACCOUNT "matthew-yun" // your Temboo account name
#define TEMBOO_APP_KEY_NAME "someKey" // your Temboo app key name
#define TEMBOO_APP_KEY "fveIrkjAVIkuNUUPE6df" // your Temboo app key
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
Keeping your account information in a separate file means you can save it once,
then just distribute the main .ino file without worrying that you forgot to delete your credentials.
*/