Permalink
Browse files

Adding examples folder

  • Loading branch information...
kevinbuck-temboo committed Oct 14, 2015
1 parent cc13383 commit a7c1ccaf25d5d1da9c66fe37193aca26d33f79cb
@@ -0,0 +1,115 @@
/*
GetYahooWeatherReport
Demonstrates making a request to the Yahoo! Weather API using Temboo from an Arduino Yún.
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 Yún is connected
to the Internet.
Looking for another API to use with your Arduino Yún? 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.
*/
@@ -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
@@ -0,0 +1,173 @@
/*
ReadATweet
Demonstrates retrieving the most recent Tweet from a user's home timeline
using Temboo from an Arduino Yún.
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 Yún
is connected to the Internet.
Want to use another social API with your Arduino Yún? 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.
*/
@@ -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
Oops, something went wrong.

0 comments on commit a7c1cca

Please sign in to comment.