1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-07 00:04:36 +03:00

Bridge library to the 1.5 format

This commit is contained in:
Fede85
2013-09-06 15:38:07 +02:00
parent effb59da4b
commit 81338e245b
58 changed files with 10 additions and 0 deletions

View File

@@ -0,0 +1,443 @@
/*
ControlBySMS
Demonstrates using an SMS message to a Twilio account to turn an LED
on the Yun board on and off using the Temboo Arduino Yun SDK.
Sending a SMS with the text "LED ON" to your Twilio phone number
will turn on the LED on the Yun. Sending "LED OFF" will turn it off.
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 retrieve 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 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).
Normally, Twilio expects to contact a web site you provide to get a response
when an SMS message is received for your Twilio number. In this case, we
don't want to send any response (and we don't want to have to set up a web
site just to receive SMS messages.) You can use a URL that Twilio provides
for this purpose. When a message is received and sent to the Twilio "twimlets"
URL, it returns a code meaning "no response required." To set this up:
1. Log in to your Twilio account and go to this URL:
https://www.twilio.com/user/account/phone-numbers/incoming
2. Select the Twilio number you want to receive SMS messages at.
3. Put this URL in the "SMS Request URL" field:
http://twimlets.com/echo?Twiml=%3CResponse%3E%3C%2FResponse%3E
See this link to Twilio's FAQ for details:
https://www.twilio.com/help/faq/sms/how-can-i-receive-sms-messages-without-responding
4. Click the "Save Changes" button at the bottom of the page.
Your account will now receive SMS messages, but won't send any responses.
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 <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.
// the Account SID from your Twilio account
const String TWILIO_ACCOUNT_SID = "xxxxxxxxxxxxxxxxxx";
// the Auth Token from your Twilio account
const String TWILIO_AUTH_TOKEN = "xxxxxxxxxxxxxxxxx";
// only act on messages sent from this phone number. (e.g. 15415551212)
const String FROM_PHONE_NUMBER = "xxxxxxxxxxx";
// how often (in milliseconds) to check for new SMS messages.
const unsigned long SMS_CHECK_PERIOD = 60000;
// keep track of when we last checked for new messages
// (initialize it to SMS_CHECK_PERIOD seconds ago so
// we do the first check as soon as the sketch starts.)
unsigned long lastSMSCheckTime = -SMS_CHECK_PERIOD;
// keep track of the ID of the last SMS message we processed.
// (we only need to process newer messages)
String lastSid;
// we'll be turning the LED built in to the Yun on and off
// to simulate controlling some device. That LED is on pin 13.
int LED_PIN = 13;
int numRuns = 1; // execution count, so this 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);
// tell the board to treat the LED pin as an output.
pinMode(LED_PIN, OUTPUT);
// start with the LED off
digitalWrite(LED_PIN, LOW);
// initialize the connection to the Linino processor.
Bridge.begin();
// Twilio will report old SMS messages. We want to
// ignore any existing control messages when we start.
Serial.println("Ignoring any existing control messages...");
checkForMessages(true);
}
void loop()
{
// get the number of milliseconds the CPU has been running.
unsigned long now = millis();
// see if it's time to check for new SMS messages.
if (now - lastSMSCheckTime >= SMS_CHECK_PERIOD) {
// it's time to check for new messages
// save this time so we know when to check next
lastSMSCheckTime = now;
if (numRuns <= maxRuns) {
Serial.println("Checking for new SMS messages - Run #" + String(numRuns++));
// execute the choreo and don't ignore control messages.
checkForMessages(false);
} else {
Serial.println("Already ran " + String(maxRuns) + " times.");
}
}
}
/*
This function executes the Twilio > SMSMessages > ListMessages choreo
and processes the results.
If ignoreCommands is 'true', this function will read and process messages
updating 'lastSid', but will not actually take any action on any commands
found. This is so we can ignore any old control messages when we start.
If ignoreCommands is 'false', control messages WILL be acted on.
*/
void checkForMessages(bool ignoreCommands) {
// we need a TembooChoreo object to send a Choreo request to Temboo
TembooChoreo ListMessagesChoreo;
ListMessagesChoreo.begin();
// set Temboo account credentials
ListMessagesChoreo.setAccountName(TEMBOO_ACCOUNT);
ListMessagesChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
ListMessagesChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Twilio > SMSMessages > ListMessages)
ListMessagesChoreo.setChoreo("/Library/Twilio/SMSMessages/ListMessages");
// set the choreo inputs
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/ListMessages/
// for complete details about the inputs for this Choreo
// the first input is a your Twilio AccountSID
ListMessagesChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID);
// next is your Twilio Auth Token
ListMessagesChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN);
// we only want to know about messages sent from our designated phone number
ListMessagesChoreo.addInput("From", FROM_PHONE_NUMBER);
// Twilio can return information about up to 1000 messages at a time.
// we're only interested in the 3 most recent ones. Note that if
// this account receives lots of messages in quick succession,
// (more than 3 per minute in this case), we might miss some control
// messages. But if we request too many messages, we might run out of
// memory on the Arduino side of the Yun.
ListMessagesChoreo.addInput("PageSize", "3");
// We want the response in XML format to process with our
// XPath output filters.
ListMessagesChoreo.addInput("ResponseFormat", "xml");
// we don't want everything from the output, just the
// message IDs (the Sids) and the message texts
ListMessagesChoreo.addOutputFilter("sid", "Sid", "Response");
ListMessagesChoreo.addOutputFilter("text", "Body", "Response");
// tell the Choreo to run and wait for the results. The
// return code (returnCode) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int returnCode = ListMessagesChoreo.run();
// a return code of zero (0) means success
if (returnCode == 0) {
// Need a string to hold the list of message IDs.
String messageSids;
// Need a string to hold the texts of the messages.
String messageTexts;
// when the choreo results are available, process them.
// the output filters we specified will return comma delimited
// lists containing the Sids and texts of the messages
// from our designated phone number.
while(ListMessagesChoreo.available()) {
// output names are terminated with '\x1F' characters.
String name = ListMessagesChoreo.readStringUntil('\x1F');
name.trim();
//Serial.println(name);
// output values are terminated with '\x1E' characters.
String data = ListMessagesChoreo.readStringUntil('\x1E');
data.trim();
//Serial.println(data);
// assign the data to the appropriate string based on the name
if (name == "sid") {
messageSids = data;
} else if (name == "text") {
messageTexts = data;
}
}
// done reading output, close the Choreo to free up resources.
ListMessagesChoreo.close();
// parse the comma delimited lists of messages and Sids
processMessages(messageTexts, messageSids, ignoreCommands);
} else {
// a non-zero return code means there was an error
// read and print the error message
while(ListMessagesChoreo.available()) {
char c = ListMessagesChoreo.read();
Serial.print(c);
}
}
}
/*
This function processes the lists of message texts and Sids.
If a message contains a comma as part of the
message text, that message will be enclosed in double quotes
(") in the list. Example:
A message,"Hey, now",Another message text
If the message contains double quotes, it will be enclosed in
double quotes AND the internal quotes will be doubled.
Example:
"Hi ""Sam"" the man", Led on
NOTE! We are assuming that Twilio returns more recent messages
first. This isn't officially documented by Twilio, but we've
not seen any other case.
'messageTexts' is a String containing a comma separated list of
message texts with commas and quotes escaped as described above.
'messageSids' is a String containing a comma separated list of
message Sids. Sids should not contain embedded commas or quotes.
'ignoreCommands' is a boolean. 'true' means and control messages
will not be acted upon. 'false' means control messages will be
acted upon in the usual way.
*/
void processMessages(String messageTexts, String messageSids, bool ignoreCommands) {
// proceed if we received at least one message
if (messageSids.length() > 0) {
int i = -1;
int sidsStart = 0;
int textsStart = 0;
String sid;
String text;
bool ledUpdated = false;
// go through the list until we run out of items
// or otherwise know we can stop
do {
// Output filter list items are separated by commas
// find the start of the next item in the list
i = messageSids.indexOf(',', sidsStart);
if (i >= 0) {
//extract a single Sid from the list.
sid = messageSids.substring(sidsStart, i);
sidsStart = i + 1;
// find the start of the next text in the list.
// Note that we have to be prepared to handle embedded
// quotes and commans in the message texts.
// The standard Arduino String class doesn't handle
// this, so we have to write our own function to do it.
i = quotedIndexOf(messageTexts, ',', textsStart);
if (i >= 0) {
// extract a single message text from the list.
text = messageTexts.substring(textsStart, i);
textsStart = i + 1;
// process the Sid and text to see if it's a
// control message.
ledUpdated = processMessage(sid, text, ignoreCommands);
}
} else {
// the last item in the lists won't have a comma at the end,
// so we have to handle them specially.
// Since we know this is the last item, we can just
// take the rest of the string for the Sid and text.
sid = messageSids.substring(sidsStart);
text = messageTexts.substring(textsStart);
// process the last item.
ledUpdated = processMessage(sid, text, ignoreCommands);
}
// keep going until either we run out of list items
// or we run into a message we processed on a previous run.
} while ((i >=0) && (sid != lastSid));
// print what we've found to the serial monitor,
// just so we can see what's going on.
if (sid == lastSid) {
if (ledUpdated)
Serial.println("Control message processed.");
else
Serial.println("No new control messages received.");
} else {
Serial.println("No control messages received.");
}
} else {
Serial.println("No messages found");
}
}
/*
This function knows how to tell if a message is a control message
or not. It also knows know to control whatever it is we're controlling
(the state of the LED on pin 13 in this case.)
A message with the text "LED ON" turns the LED on.
A message with the text "LED OFF" turns the LED off.
(Case is ignored.)
If 'ignoreCommands' is true, the actions described above will NOT
take place.
It also updates the 'lastSid' global variable when
a control message is processed.
It returns 'true' if the message was a control message, and
'false' if it wasn't or if we've already processed this message.
*/
bool processMessage(String sid, String text, bool ignoreCommands) {
// a flag to indicate whether this was a control message or not
bool ledUpdated = false;
// if we haven't already processed this message
if (sid != lastSid) {
if (text.equalsIgnoreCase("LED ON")) {
if (!ignoreCommands) {
//turn on the LED
digitalWrite(LED_PIN, HIGH);
Serial.println("LED ON");
}
ledUpdated = true;
} else if (text.equalsIgnoreCase("LED OFF")) {
if (!ignoreCommands) {
//turn off the LED
digitalWrite(LED_PIN, LOW);
Serial.println("LED OFF");
}
ledUpdated = true;
}
// If the LED state was updated, remember the Sid if this message.
if (ledUpdated)
lastSid = sid;
}
return ledUpdated;
}
/*
This function finds the index of a delimiter character in a String,
ignoring delimiters that appear inside double-quotes.
*/
int quotedIndexOf(String s, char delim, int start) {
bool inQuotes = false;
char c;
int index = -1;
const char QUOTE = '"';
do {
c = s[start++];
if (c == QUOTE)
inQuotes = !inQuotes;
else if (c == delim && !inQuotes)
index = --start;
} while ((c != '\0') && (index < 0));
return index;
}
/*
IMPORTANT NOTE: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
by inserting your own Temboo account name and app key information. The contents of the file should
look like:
#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
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
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,5 @@
#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

View File

@@ -0,0 +1,115 @@
/*
GetYahooWeatherReport
Demonstrates making a request to the Yahoo! Weather API using Temboo from an Arduino Yun.
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 to use with your Arduino Yun? We've got over 100 in our Library!
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
// the address for which a weather forecast will be retrieved
String ADDRESS_FOR_FORECAST = "104 Franklin St., New York NY 10013";
int numRuns = 1; // execution count, so that this doesn't run forever
int maxRuns = 10; // max number of times the Yahoo WeatherByAddress 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 GetWeatherByAddress - Run #" + String(numRuns++) + "...");
// create a TembooChoreo object to send a Choreo request to Temboo
TembooChoreo GetWeatherByAddressChoreo;
// invoke the Temboo client
GetWeatherByAddressChoreo.begin();
// add your temboo account info
GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT);
GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY);
// set the name of the choreo we want to run
GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress");
// set choreo inputs; in this case, the address for which to retrieve weather data
// the Temboo client provides standardized calls to 100+ cloud APIs
GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST);
// add an output filter to extract the name of the city.
GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response");
// add an output filter to extract the current temperature
GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response");
// add an output filter to extract the date and time of the last report.
GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response");
// run the choreo
GetWeatherByAddressChoreo.run();
// when the choreo results are available, print them to the serial monitor
while(GetWeatherByAddressChoreo.available()) {
char c = GetWeatherByAddressChoreo.read();
Serial.print(c);
}
GetWeatherByAddressChoreo.close();
}
Serial.println("Waiting...");
Serial.println("");
delay(30000); // wait 30 seconds between GetWeatherByAddress calls
}
/*
IMPORTANT NOTE: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
by inserting your own Temboo account name and app key information. The contents of the file should
look like:
#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
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Keeping your account information in a separate file means you can share the main .ino file without worrying
that you forgot to delete your credentials.
*/

View File

@@ -0,0 +1,4 @@
#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

View File

@@ -0,0 +1,173 @@
/*
ReadATweet
Demonstrates retrieving the most recent Tweet from a user's home timeline
using Temboo from an Arduino Yun.
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.
Want to use another social API with your Arduino Yun? We've got Facebook,
Google+, Instagram, Tumblr and more in our Library!
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.
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 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()
{
// while we haven't reached the max number of runs...
if (numRuns <= maxRuns) {
Serial.println("Running ReadATweet - Run #" + String(numRuns++));
TembooChoreo HomeTimelineChoreo;
// invoke the Temboo client.
// NOTE that the client must be reinvoked, and repopulated with
// appropriate arguments, each time its run() method is called.
HomeTimelineChoreo.begin();
// set Temboo account credentials
HomeTimelineChoreo.setAccountName(TEMBOO_ACCOUNT);
HomeTimelineChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
HomeTimelineChoreo.setAppKey(TEMBOO_APP_KEY);
// tell the Temboo client which Choreo to run (Twitter > Timelines > HomeTimeline)
HomeTimelineChoreo.setChoreo("/Library/Twitter/Timelines/HomeTimeline");
// set the required choreo inputs
// see https://www.temboo.com/library/Library/Twitter/Timelines/HomeTimeline/
// for complete details about the inputs for this Choreo
HomeTimelineChoreo.addInput("Count", "1"); // the max number of Tweets to return from each request
HomeTimelineChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
HomeTimelineChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY);
HomeTimelineChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET);
// next, we'll define two output filters that let us specify the
// elements of the response from Twitter that we want to receive.
// see the examples at http://www.temboo.com/arduino
// for more on using output filters
// we want the text of the tweet
HomeTimelineChoreo.addOutputFilter("tweet", "/[1]/text", "Response");
// and the name of the author
HomeTimelineChoreo.addOutputFilter("author", "/[1]/user/screen_name", "Response");
// tell the Process to run and wait for the results. The
// return code will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int returnCode = HomeTimelineChoreo.run();
// a response code of 0 means success; print the API response
if(returnCode == 0) {
String author; // a String to hold the tweet author's name
String tweet; // a String to hold the text of the tweet
// choreo outputs are returned as key/value pairs, delimited with
// newlines and record/field terminator characters, for example:
// Name1\n\x1F
// Value1\n\x1E
// Name2\n\x1F
// Value2\n\x1E
// see the examples at http://www.temboo.com/arduino for more details
// we can read this format into separate variables, as follows:
while(HomeTimelineChoreo.available()) {
// read the name of the output item
String name = HomeTimelineChoreo.readStringUntil('\x1F');
name.trim();
// read the value of the output item
String data = HomeTimelineChoreo.readStringUntil('\x1E');
data.trim();
// assign the value to the appropriate String
if (name == "tweet") {
tweet = data;
} else if (name == "author") {
author = data;
}
}
Serial.println("@" + author + " - " + tweet);
} else {
// there was an error
// print the raw output from the choreo
while(HomeTimelineChoreo.available()) {
char c = HomeTimelineChoreo.read();
Serial.print(c);
}
}
HomeTimelineChoreo.close();
}
Serial.println("Waiting...");
delay(90000); // wait 90 seconds between HomeTimeline calls
}
/*
IMPORTANT NOTE: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
by inserting your own Temboo account name and app key information. The contents of the file should
look like:
#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
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Keeping your account information in a separate file means you can share the main .ino file without worrying
that you forgot to delete your credentials.
*/

View File

@@ -0,0 +1,4 @@
#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

View File

@@ -0,0 +1,138 @@
/*
SendATweet
Demonstrates sending a tweet via a Twitter account using Temboo from an Arduino Yun.
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. Note that since this
sketch creates a new tweet, your application will need to be configured with
read+write permissions. 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.
Want to use another social API with your Arduino Yun? We've got Facebook,
Google+, Instagram, Tumblr and more in our Library!
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.
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 = 3; // the max number of times the Twitter Update 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++) + "...");
// define the text of the tweet we want to send
String tweetText("My Arduino Yun has been running for " + String(millis()) + " milliseconds.");
TembooChoreo StatusesUpdateChoreo;
// invoke the Temboo client
// NOTE that the client must be reinvoked, and repopulated with
// appropriate arguments, each time its run() method is called.
StatusesUpdateChoreo.begin();
// set Temboo account credentials
StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT);
StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
StatusesUpdateChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Twitter > Tweets > StatusesUpdate)
StatusesUpdateChoreo.setChoreo("/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.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY);
StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET);
// and the tweet we want to send
StatusesUpdateChoreo.addInput("StatusUpdate", tweetText);
// tell the Process to run and wait for the results. The
// return code (returnCode) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int returnCode = StatusesUpdateChoreo.run();
// a return code of zero (0) means everything worked
if (returnCode == 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()) {
char c = StatusesUpdateChoreo.read();
Serial.print(c);
}
}
StatusesUpdateChoreo.close();
// do nothing for the next 90 seconds
Serial.println("Waiting...");
delay(90000);
}
}
/*
IMPORTANT NOTE: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
by inserting your own Temboo account name and app key information. The contents of the file should
look like:
#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
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Keeping your account information in a separate file means you can share the main .ino file without worrying
that you forgot to delete your credentials.
*/

View File

@@ -0,0 +1,4 @@
#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

View File

@@ -0,0 +1,137 @@
/*
SendAnEmail
Demonstrates sending an email via a Google Gmail account using Temboo from an Arduino Yun.
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 Gmail to send the email, you'll also need a valid
Google Gmail account. The sketch needs the username and password you use
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.
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.
// your Gmail username, formatted as a complete email 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";
// a flag to indicate whether we've tried to send the email yet or not
boolean attempted = false;
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 email if we haven't already tried
if (!attempted) {
Serial.println("Running SendAnEmail...");
TembooChoreo SendEmailChoreo;
// invoke the Temboo client
// NOTE that the client must be reinvoked, and repopulated with
// appropriate arguments, each time its run() method is called.
SendEmailChoreo.begin();
// set Temboo account credentials
SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT);
SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
SendEmailChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Google > Gmail > SendEmail)
SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail");
// set the required choreo inputs
// see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/
// for complete details about the inputs for this Choreo
// the first input is your Gmail email address.
SendEmailChoreo.addInput("Username", GMAIL_USER_NAME);
// next is your Gmail password.
SendEmailChoreo.addInput("Password", GMAIL_PASSWORD);
// who to send the email to
SendEmailChoreo.addInput("ToAddress", TO_EMAIL_ADDRESS);
// then a subject line
SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature");
// next comes the message body, the main content of the email
SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!");
// tell the Choreo to run and wait for the results. The
// return code (returnCode) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int returnCode = SendEmailChoreo.run();
// a return code of zero (0) means everything worked
if (returnCode == 0) {
Serial.println("Success! Email sent!");
} else {
// a non-zero return code means there was an error
// read and print the error message
while (SendEmailChoreo.available()) {
char c = SendEmailChoreo.read();
Serial.print(c);
}
}
SendEmailChoreo.close();
// set the flag showing we've tried
attempted = true;
}
}
/*
IMPORTANT NOTE: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
by inserting your own Temboo account name and app key information. The contents of the file should
look like:
#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
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Keeping your account information in a separate file means you can share the main .ino file without worrying
that you forgot to delete your credentials.
*/

View File

@@ -0,0 +1,4 @@
#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

View File

@@ -0,0 +1,154 @@
/*
SendAnSMS
Demonstrates sending an SMS via Twilio using Temboo from an Arduino Yun.
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 to use with your Arduino Yun? We've got over 100 in our Library!
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.
// 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";
// a flag to indicate whether we've attempted to send the SMS yet or not
boolean attempted = false;
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 (!attempted) {
Serial.println("Running SendAnSMS...");
// we need a Process object to send a Choreo request to Temboo
TembooChoreo SendSMSChoreo;
// invoke the Temboo client
// NOTE that the client must be reinvoked and repopulated with
// appropriate arguments each time its run() method is called.
SendSMSChoreo.begin();
// set Temboo account credentials
SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT);
SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
SendSMSChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Twilio > SMSMessages > SendSMS)
SendSMSChoreo.setChoreo("/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.addInput("AccountSID", TWILIO_ACCOUNT_SID);
// next is your Auth Token
SendSMSChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN);
// next is your Twilio phone number
SendSMSChoreo.addInput("From", TWILIO_NUMBER);
// next, what number to send the SMS to
SendSMSChoreo.addInput("To", RECIPIENT_NUMBER);
// finally, the text of the message to send
SendSMSChoreo.addInput("Body", "Hey, there! This is a message from your Arduino Yun!");
// tell the Process to run and wait for the results. The
// return code (returnCode) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int returnCode = SendSMSChoreo.run();
// a return code of zero (0) means everything worked
if (returnCode == 0) {
Serial.println("Success! SMS sent!");
} else {
// a non-zero return code means there was an error
// read and print the error message
while (SendSMSChoreo.available()) {
char c = SendSMSChoreo.read();
Serial.print(c);
}
}
SendSMSChoreo.close();
// set the flag indicatine we've tried once.
attempted=true;
}
}
/*
IMPORTANT NOTE: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
by inserting your own Temboo account name and app key information. The contents of the file should
look like:
#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
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Keeping your account information in a separate file means you can share the main .ino file without worrying
that you forgot to delete your credentials.
*/

View File

@@ -0,0 +1,5 @@
#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

View File

@@ -0,0 +1,178 @@
/*
SendDataToGoogleSpreadsheet
Demonstrates appending a row of data to a Google spreadsheet using Temboo from an Arduino Yun.
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 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.
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 to use with your Arduino Yun? We've got over 100 in our Library!
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information,
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.
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
// (Note that this must actually be the title of a Google spreadsheet
// that exists in your Google Drive/Docs account, and is configured
// as described above.)
const String SPREADSHEET_TITLE = "your-spreadsheet-title";
const unsigned long RUN_INTERVAL_MILLIS = 60000; // how often to run the Choreo (in milliseconds)
// the last time we ran the Choreo
// (initialized to 60 seconds ago so the
// Choreo is run immediately when we start up)
unsigned long lastRun = (unsigned long)-60000;
void setup() {
// for debugging, wait until a serial console is connected
Serial.begin(9600);
delay(4000);
while(!Serial);
Serial.print("Initializing the bridge...");
Bridge.begin();
Serial.println("Done");
}
void loop()
{
// get the number of milliseconds this sketch has been running
unsigned long now = millis();
// run again if it's been 60 seconds since we last ran
if (now - lastRun >= RUN_INTERVAL_MILLIS) {
// remember 'now' as the last time we ran the choreo
lastRun = now;
Serial.println("Getting sensor value...");
// get the value we want to append to our spreadsheet
unsigned long sensorValue = getSensorValue();
Serial.println("Appending value to spreadsheet...");
// we need a Process object to send a Choreo request to Temboo
TembooChoreo AppendRowChoreo;
// invoke the Temboo client
// NOTE that the client must be reinvoked and repopulated with
// appropriate arguments each time its run() method is called.
AppendRowChoreo.begin();
// set Temboo account credentials
AppendRowChoreo.setAccountName(TEMBOO_ACCOUNT);
AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
AppendRowChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Google > Spreadsheets > AppendRow)
AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");
// set the required Choreo inputs
// see https://www.temboo.com/library/Library/Google/Spreadsheets/AppendRow/
// for complete details about the inputs for this Choreo
// your Google username (usually your email address)
AppendRowChoreo.addInput("Username", GOOGLE_USERNAME);
// your Google account password
AppendRowChoreo.addInput("Password", GOOGLE_PASSWORD);
// the title of the spreadsheet you want to append to
// NOTE: substitute your own value, retaining the "SpreadsheetTitle:" prefix.
AppendRowChoreo.addInput("SpreadsheetTitle", SPREADSHEET_TITLE);
// convert the time and sensor values to a comma separated string
String rowData(now);
rowData += ",";
rowData += sensorValue;
// add the RowData input item
AppendRowChoreo.addInput("RowData", rowData);
// run the Choreo and wait for the results
// The return code (returnCode) will indicate success or failure
unsigned int returnCode = AppendRowChoreo.run();
// return code of zero (0) means success
if (returnCode == 0) {
Serial.println("Success! Appended " + rowData);
Serial.println("");
} else {
// return code of anything other than zero means failure
// read and display any error messages
while (AppendRowChoreo.available()) {
char c = AppendRowChoreo.read();
Serial.print(c);
}
}
AppendRowChoreo.close();
}
}
// this function simulates reading the value of a sensor
unsigned long getSensorValue() {
return analogRead(A0);
}
/*
IMPORTANT NOTE: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
by inserting your own Temboo account name and app key information. The contents of the file should
look like:
#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
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Keeping your account information in a separate file means you can share the main .ino file without worrying
that you forgot to delete your credentials.
*/

View File

@@ -0,0 +1,5 @@
#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

View File

@@ -0,0 +1,5 @@
#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

View File

@@ -0,0 +1,171 @@
/*
ToxicFacilitiesSearch
Demonstrates making a request to the Envirofacts API using Temboo from an Arduino Yun.
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 to use with your Arduino Yun? We've got over 100 in our Library!
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
// the zip code to search for toxin-emitting facilities
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
TembooChoreo FacilitiesSearchByZipChoreo;
// invoke the Temboo client
// NOTE that the client must be reinvoked and repopulated with
// appropriate arguments each time its run() method is called.
FacilitiesSearchByZipChoreo.begin();
// set Temboo account credentials
FacilitiesSearchByZipChoreo.setAccountName(TEMBOO_ACCOUNT);
FacilitiesSearchByZipChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
FacilitiesSearchByZipChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (EnviroFacts > Toxins > FacilitiesSearchByZip)
FacilitiesSearchByZipChoreo.setChoreo("/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.addInput("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.addOutputFilter("fac", "FACILITY_NAME", "Response");
FacilitiesSearchByZipChoreo.addOutputFilter("addr", "STREET_ADDRESS", "Response");
// run the choreo
unsigned int returnCode = FacilitiesSearchByZipChoreo.run();
if (returnCode == 0) {
String facilities;
String addresses;
// 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") {
facilities = data;
} else if (name == "addr") {
addresses = 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 (facilities.length() > 0) {
int i = -1;
int facilityStart = 0;
int addressStart = 0;
String facility;
String address;
do {
i = facilities.indexOf(',', facilityStart);
if (i >= 0) {
facility = facilities.substring(facilityStart, i);
facilityStart = i + 1;
}
i = addresses.indexOf(',', addressStart);
if (i >= 0) {
address = addresses.substring(addressStart, i);
addressStart = i + 1;
}
if (i >= 0) {
printResult(facility, address);
}
}while (i >= 0);
facility = facilities.substring(facilityStart);
address = addresses.substring(addressStart);
printResult(facility, address);
} else {
Serial.println("No facilities found in zip code " + US_ZIP_CODE);
}
} else {
while(FacilitiesSearchByZipChoreo.available()) {
char c = FacilitiesSearchByZipChoreo.read();
Serial.print(c);
}
}
}
Serial.println("Waiting...");
Serial.println("");
delay(30000); // wait 30 seconds between calls
}
// a simple utility function, to output the facility name and address in the serial monitor.
void printResult(String facility, String address) {
Serial.print(facility);
Serial.print(" - ");
Serial.println(address);
}
/*
IMPORTANT NOTE: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
by inserting your own Temboo account name and app key information. The contents of the file should
look like:
#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
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Keeping your account information in a separate file means you can share the main .ino file without worrying
that you forgot to delete your credentials.
*/

View File

@@ -0,0 +1,5 @@
#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

View File

@@ -0,0 +1,132 @@
/*
UpdateFacebookStatus
Demonstrates sending a Facebook status update using Temboo from an Arduino Yun.
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.
Want to use another social API with your Arduino Yun? We've got Twitter, Google+,
Instagram, Tumblr and more in our Library!
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information,
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// Note that for additional security and reusability, you could
// use a #define statement to specify this value in a .h file.
// the Facebook Access Token, which can be obtained using the Temboo OAuth Wizard or Choreos
const String FACEBOOK_ACCESS_TOKEN = "xxxxxxxxxx";
int numRuns = 1; // 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
TembooChoreo SetStatusChoreo;
// invoke the Temboo client
// NOTE that the client must be reinvoked and repopulated with
// appropriate arguments each time its run() method is called.
SetStatusChoreo.begin();
// set Temboo account credentials
SetStatusChoreo.setAccountName(TEMBOO_ACCOUNT);
SetStatusChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
SetStatusChoreo.setAppKey(TEMBOO_APP_KEY);
// tell the Temboo client which Choreo to run (Facebook > Publishing > SetStatus)
SetStatusChoreo.setChoreo("/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.addInput("AccessToken", FACEBOOK_ACCESS_TOKEN);
SetStatusChoreo.addInput("Message", statusMsg);
// tell the Process to run and wait for the results. The
// return code (returnCode) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int returnCode = SetStatusChoreo.run();
// print the response code and API response.
Serial.println("Response code: " + String(returnCode));
// 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()) {
char c = SetStatusChoreo.read();
Serial.print(c);
}
SetStatusChoreo.close();
}
Serial.println("Waiting...");
Serial.println("");
delay(30000); // wait 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'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
by inserting your own Temboo account name and app key information. The contents of the file should
look like:
#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
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Keeping your account information in a separate file means you can share the main .ino file without worrying
that you forgot to delete your credentials.
*/

View File

@@ -0,0 +1,5 @@
#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

View File

@@ -0,0 +1,208 @@
/*
UploadToDropbox
Demonstrates uploading a file to a Dropbox account using Temboo from an Arduino Yun.
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 app and accompanying OAuth credentials.
To create a Dropbox app, visit https://www.dropbox.com/developers/apps and
do the following:
1. Create a "Dropbox API app"
2. Select "Files and datastores"
3. Select "Yes - my app only needs access to the files it creates."
Once you've created your app, follow the instructions at
https://www.temboo.com/library/Library/Dropbox/OAuth/ to run the Initialize and Finalize
OAuth Choreos. These Choreos complete the OAuth handshake and retrieve your Dropbox OAuth access tokens.
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
to the Internet.
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
This example code is in the public domain.
*/
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.
// 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
TembooChoreo UploadFileChoreo;
// invoke the Temboo client
// NOTE that the client must be reinvoked and repopulated with
// appropriate arguments each time its run() method is called.
UploadFileChoreo.begin();
// set Temboo account credentials
UploadFileChoreo.setAccountName(TEMBOO_ACCOUNT);
UploadFileChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
UploadFileChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Dropbox > FilesAndMetadata > UploadFile)
UploadFileChoreo.setChoreo("/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.addInput("FileName", "ArduinoTest.txt");
// next, the root folder on Dropbox relative to which the file path is specified.
// to work with the Dropbox app you created earlier, this should be left as "sandbox"
// if your Dropbox app has full access to your files, specify "dropbox"
UploadFileChoreo.addInput("Root","sandbox");
// next, the Base64 encoded file data to upload
UploadFileChoreo.addInput("FileContents", base64EncodedData);
// finally, the Dropbox OAuth credentials defined above
UploadFileChoreo.addInput("AppSecret", DROPBOX_APP_SECRET);
UploadFileChoreo.addInput("AccessToken", DROPBOX_ACCESS_TOKEN);
UploadFileChoreo.addInput("AccessTokenSecret", DROPBOX_ACCESS_TOKEN_SECRET);
UploadFileChoreo.addInput("AppKey", DROPBOX_APP_KEY);
// tell the Process to run and wait for the results. The
// return code (returnCode) will tell us whether the Temboo client
// was able to send our request to the Temboo servers
unsigned int returnCode = UploadFileChoreo.run();
// a return code of zero (0) means everything worked
if (returnCode == 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()) {
char c = UploadFileChoreo.read();
Serial.print(c);
}
UploadFileChoreo.close();
Serial.println("Waiting...");
}
delay(30000); // wait 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
TembooChoreo Base64EncodeChoreo;
// invoke the Temboo client
Base64EncodeChoreo.begin();
// set Temboo account credentials
Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT);
Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY);
// identify the Temboo Library choreo to run (Utilities > Encoding > Base64Encode)
Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode");
// set choreo inputs
Base64EncodeChoreo.addInput("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: TembooAccount.h:
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
by inserting your own Temboo account name and app key information. The contents of the file should
look like:
#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
You can find your Temboo App Key information on the Temboo website,
under My Account > Application Keys
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Keeping your account information in a separate file means you can share the main .ino file without worrying
that you forgot to delete your credentials.
*/