Skip to content

Commit fbd208e

Browse files
Merge pull request #3 from temboo/release1.1.4
Adding examples folder
2 parents cc13383 + a7c1cca commit fbd208e

File tree

20 files changed

+1500
-2
lines changed

20 files changed

+1500
-2
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
GetYahooWeatherReport
3+
4+
Demonstrates making a request to the Yahoo! Weather API using Temboo from an Arduino Yún.
5+
6+
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
7+
8+
A Temboo account and application key are necessary to run all Temboo examples.
9+
If you don't already have one, you can register for a free Temboo account at
10+
http://www.temboo.com
11+
12+
This example assumes basic familiarity with Arduino sketches, and that your Yún is connected
13+
to the Internet.
14+
15+
Looking for another API to use with your Arduino Yún? We've got over 100 in our Library!
16+
17+
This example code is in the public domain.
18+
*/
19+
20+
#include <Bridge.h>
21+
#include <Temboo.h>
22+
#include "TembooAccount.h" // contains Temboo account information
23+
// as described in the footer comment below
24+
25+
26+
// the address for which a weather forecast will be retrieved
27+
String ADDRESS_FOR_FORECAST = "104 Franklin St., New York NY 10013";
28+
29+
int numRuns = 1; // execution count, so that this doesn't run forever
30+
int maxRuns = 10; // max number of times the Yahoo WeatherByAddress Choreo should be run
31+
32+
33+
void setup() {
34+
Serial.begin(9600);
35+
36+
// for debugging, wait until a serial console is connected
37+
delay(4000);
38+
while(!Serial);
39+
Bridge.begin();
40+
41+
}
42+
43+
void loop()
44+
{
45+
// while we haven't reached the max number of runs...
46+
if (numRuns <= maxRuns) {
47+
48+
// print status
49+
Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "...");
50+
51+
// create a TembooChoreo object to send a Choreo request to Temboo
52+
TembooChoreo GetWeatherByAddressChoreo;
53+
54+
// invoke the Temboo client
55+
GetWeatherByAddressChoreo.begin();
56+
57+
// add your temboo account info
58+
GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT);
59+
GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
60+
GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY);
61+
62+
// set the name of the choreo we want to run
63+
GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress");
64+
65+
// set choreo inputs; in this case, the address for which to retrieve weather data
66+
// the Temboo client provides standardized calls to 100+ cloud APIs
67+
GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST);
68+
69+
// add an output filter to extract the name of the city.
70+
GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response");
71+
72+
// add an output filter to extract the current temperature
73+
GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response");
74+
75+
// add an output filter to extract the date and time of the last report.
76+
GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response");
77+
78+
// run the choreo
79+
GetWeatherByAddressChoreo.run();
80+
81+
// when the choreo results are available, print them to the serial monitor
82+
while(GetWeatherByAddressChoreo.available()) {
83+
84+
char c = GetWeatherByAddressChoreo.read();
85+
Serial.print(c);
86+
}
87+
GetWeatherByAddressChoreo.close();
88+
89+
}
90+
91+
Serial.println("Waiting...");
92+
Serial.println("");
93+
delay(30000); // wait 30 seconds between GetWeatherByAddress calls
94+
}
95+
96+
/*
97+
IMPORTANT NOTE: TembooAccount.h:
98+
99+
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
100+
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
101+
by inserting your own Temboo account name and app key information. The contents of the file should
102+
look like:
103+
104+
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
105+
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
106+
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
107+
108+
You can find your Temboo App Key information on the Temboo website,
109+
under My Account > Application Keys
110+
111+
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
112+
113+
Keeping your account information in a separate file means you can share the main .ino file without worrying
114+
that you forgot to delete your credentials.
115+
*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
2+
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
3+
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
4+
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
ReadATweet
3+
4+
Demonstrates retrieving the most recent Tweet from a user's home timeline
5+
using Temboo from an Arduino Yún.
6+
7+
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
8+
9+
A Temboo account and application key are necessary to run all Temboo examples.
10+
If you don't already have one, you can register for a free Temboo account at
11+
http://www.temboo.com
12+
13+
In order to run this sketch, you'll need to register an application using
14+
the Twitter dev console at https://dev.twitter.com. After creating the
15+
app, you'll find OAuth credentials for that application under the "OAuth Tool" tab.
16+
Substitute these values for the placeholders below.
17+
18+
This example assumes basic familiarity with Arduino sketches, and that your Yún
19+
is connected to the Internet.
20+
21+
Want to use another social API with your Arduino Yún? We've got Facebook,
22+
Google+, Instagram, Tumblr and more in our Library!
23+
24+
This example code is in the public domain.
25+
*/
26+
27+
#include <Bridge.h>
28+
#include <Temboo.h>
29+
#include "TembooAccount.h" // contains Temboo account information
30+
// as described in the footer comment below
31+
32+
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
33+
34+
// Note that for additional security and reusability, you could
35+
// use #define statements to specify these values in a .h file.
36+
const String TWITTER_ACCESS_TOKEN = "your-twitter-access-token";
37+
const String TWITTER_ACCESS_TOKEN_SECRET = "your-twitter-access-token-secret";
38+
const String TWITTER_CONSUMER_KEY = "your-twitter-consumer-key";
39+
const String TWITTER_CONSUMER_SECRET = "your-twitter-consumer-secret";
40+
41+
int numRuns = 1; // execution count, so this doesn't run forever
42+
int maxRuns = 10; // the max number of times the Twitter HomeTimeline Choreo should run
43+
44+
void setup() {
45+
Serial.begin(9600);
46+
47+
// For debugging, wait until a serial console is connected.
48+
delay(4000);
49+
while(!Serial);
50+
Bridge.begin();
51+
}
52+
void loop()
53+
{
54+
// while we haven't reached the max number of runs...
55+
if (numRuns <= maxRuns) {
56+
Serial.println("Running ReadATweet - Run #" + String(numRuns++));
57+
58+
TembooChoreo HomeTimelineChoreo;
59+
60+
// invoke the Temboo client.
61+
// NOTE that the client must be reinvoked, and repopulated with
62+
// appropriate arguments, each time its run() method is called.
63+
HomeTimelineChoreo.begin();
64+
65+
// set Temboo account credentials
66+
HomeTimelineChoreo.setAccountName(TEMBOO_ACCOUNT);
67+
HomeTimelineChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
68+
HomeTimelineChoreo.setAppKey(TEMBOO_APP_KEY);
69+
70+
// tell the Temboo client which Choreo to run (Twitter > Timelines > HomeTimeline)
71+
HomeTimelineChoreo.setChoreo("/Library/Twitter/Timelines/HomeTimeline");
72+
73+
74+
// set the required choreo inputs
75+
// see https://www.temboo.com/library/Library/Twitter/Timelines/HomeTimeline/
76+
// for complete details about the inputs for this Choreo
77+
78+
HomeTimelineChoreo.addInput("Count", "1"); // the max number of Tweets to return from each request
79+
HomeTimelineChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
80+
HomeTimelineChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
81+
HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY);
82+
HomeTimelineChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET);
83+
84+
// next, we'll define two output filters that let us specify the
85+
// elements of the response from Twitter that we want to receive.
86+
// see the examples at http://www.temboo.com/arduino
87+
// for more on using output filters
88+
89+
// we want the text of the tweet
90+
HomeTimelineChoreo.addOutputFilter("tweet", "/[1]/text", "Response");
91+
92+
// and the name of the author
93+
HomeTimelineChoreo.addOutputFilter("author", "/[1]/user/screen_name", "Response");
94+
95+
96+
// tell the Process to run and wait for the results. The
97+
// return code will tell us whether the Temboo client
98+
// was able to send our request to the Temboo servers
99+
unsigned int returnCode = HomeTimelineChoreo.run();
100+
101+
// a response code of 0 means success; print the API response
102+
if(returnCode == 0) {
103+
104+
String author; // a String to hold the tweet author's name
105+
String tweet; // a String to hold the text of the tweet
106+
107+
108+
// choreo outputs are returned as key/value pairs, delimited with
109+
// newlines and record/field terminator characters, for example:
110+
// Name1\n\x1F
111+
// Value1\n\x1E
112+
// Name2\n\x1F
113+
// Value2\n\x1E
114+
115+
// see the examples at http://www.temboo.com/arduino for more details
116+
// we can read this format into separate variables, as follows:
117+
118+
while(HomeTimelineChoreo.available()) {
119+
// read the name of the output item
120+
String name = HomeTimelineChoreo.readStringUntil('\x1F');
121+
name.trim();
122+
123+
// read the value of the output item
124+
String data = HomeTimelineChoreo.readStringUntil('\x1E');
125+
data.trim();
126+
127+
// assign the value to the appropriate String
128+
if (name == "tweet") {
129+
tweet = data;
130+
} else if (name == "author") {
131+
author = data;
132+
}
133+
}
134+
135+
Serial.println("@" + author + " - " + tweet);
136+
137+
} else {
138+
// there was an error
139+
// print the raw output from the choreo
140+
while(HomeTimelineChoreo.available()) {
141+
char c = HomeTimelineChoreo.read();
142+
Serial.print(c);
143+
}
144+
}
145+
146+
HomeTimelineChoreo.close();
147+
148+
}
149+
150+
Serial.println("Waiting...");
151+
delay(90000); // wait 90 seconds between HomeTimeline calls
152+
}
153+
154+
/*
155+
IMPORTANT NOTE: TembooAccount.h:
156+
157+
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
158+
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
159+
by inserting your own Temboo account name and app key information. The contents of the file should
160+
look like:
161+
162+
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
163+
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
164+
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
165+
166+
You can find your Temboo App Key information on the Temboo website,
167+
under My Account > Application Keys
168+
169+
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
170+
171+
Keeping your account information in a separate file means you can share the main .ino file without worrying
172+
that you forgot to delete your credentials.
173+
*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
2+
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
3+
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
4+

0 commit comments

Comments
 (0)