Skip to content

Commit 6eec8e0

Browse files
author
Federico Fissore
committed
introducing Temboo library
1 parent 46a1cf6 commit 6eec8e0

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
###############################################################################
3+
#
4+
# Temboo Arduino Yun library
5+
#
6+
# Copyright 2013, Temboo Inc.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing,
15+
# software distributed under the License is distributed on an
16+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17+
# either express or implied. See the License for the specific
18+
# language governing permissions and limitations under the License.
19+
#
20+
###############################################################################
21+
*/
22+
23+
#include <Temboo.h>
24+
25+
void TembooChoreo::begin() {
26+
Process::begin("temboo");
27+
}
28+
29+
void TembooChoreo::setAccountName(const String& accountName) {
30+
addParameter("-a" + accountName);
31+
}
32+
33+
void TembooChoreo::setAppKeyName(const String& appKeyName) {
34+
addParameter("-u" + appKeyName);
35+
}
36+
37+
void TembooChoreo::setAppKey(const String& appKey) {
38+
addParameter("-p" + appKey);
39+
}
40+
41+
void TembooChoreo::setChoreo(const String& choreo) {
42+
addParameter("-c" + choreo);
43+
}
44+
45+
void TembooChoreo::setCredential(const String& credentialName) {
46+
addParameter("-e" + credentialName);
47+
}
48+
49+
void TembooChoreo::addInput(const String& inputName, const String& inputValue) {
50+
addParameter("-i" + inputName + ":" + inputValue);
51+
}
52+
53+
void TembooChoreo::addOutputFilter(const String& outputName, const String& filterPath, const String& variableName) {
54+
addParameter("-o" + outputName + ":" + filterPath + ":" + variableName);
55+
}
56+
57+
void TembooChoreo::setSettingsFileToWrite(const String& filePath) {
58+
addParameter("-w" + filePath);
59+
}
60+
61+
void TembooChoreo::setSettingsFileToRead(const String& filePath) {
62+
addParameter("-r" + filePath);
63+
}
64+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
###############################################################################
3+
#
4+
# Temboo Arduino Yun library
5+
#
6+
# Copyright 2013, Temboo Inc.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing,
15+
# software distributed under the License is distributed on an
16+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17+
# either express or implied. See the License for the specific
18+
# language governing permissions and limitations under the License.
19+
#
20+
###############################################################################
21+
*/
22+
23+
#ifndef _TEMBOO_H
24+
#define _TEMBOO_H
25+
#include <Arduino.h>
26+
#include <Process.h>
27+
28+
class TembooChoreo : public Process {
29+
30+
public:
31+
void begin();
32+
void setAccountName(const String& accountName);
33+
void setAppKeyName(const String& appKeyName);
34+
void setAppKey(const String& appKey);
35+
void setChoreo(const String& choreo);
36+
void setCredential(const String& credentialName);
37+
void addInput(const String& inputName, const String& inputValue);
38+
void addOutputFilter(const String& filterName, const String& filterPath, const String& variableName);
39+
void setSettingsFileToWrite(const String& filePath);
40+
void setSettingsFileToRead(const String& filePath);
41+
42+
};
43+
44+
#endif
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 the Temboo Arduino Yun SDK.
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 Yun is connected
13+
to the Internet.
14+
15+
Looking for another API? 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 save it once,
114+
then just distribute the main .ino file without worrying 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+

0 commit comments

Comments
 (0)