mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-06 01:08:25 +01:00
introducing Temboo library
This commit is contained in:
parent
46a1cf6f06
commit
6eec8e0922
64
hardware/arduino/avr/libraries/Temboo/Temboo.cpp
Normal file
64
hardware/arduino/avr/libraries/Temboo/Temboo.cpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# Temboo Arduino Yun library
|
||||||
|
#
|
||||||
|
# Copyright 2013, Temboo Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing,
|
||||||
|
# software distributed under the License is distributed on an
|
||||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||||
|
# either express or implied. See the License for the specific
|
||||||
|
# language governing permissions and limitations under the License.
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Temboo.h>
|
||||||
|
|
||||||
|
void TembooChoreo::begin() {
|
||||||
|
Process::begin("temboo");
|
||||||
|
}
|
||||||
|
|
||||||
|
void TembooChoreo::setAccountName(const String& accountName) {
|
||||||
|
addParameter("-a" + accountName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TembooChoreo::setAppKeyName(const String& appKeyName) {
|
||||||
|
addParameter("-u" + appKeyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TembooChoreo::setAppKey(const String& appKey) {
|
||||||
|
addParameter("-p" + appKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TembooChoreo::setChoreo(const String& choreo) {
|
||||||
|
addParameter("-c" + choreo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TembooChoreo::setCredential(const String& credentialName) {
|
||||||
|
addParameter("-e" + credentialName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TembooChoreo::addInput(const String& inputName, const String& inputValue) {
|
||||||
|
addParameter("-i" + inputName + ":" + inputValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TembooChoreo::addOutputFilter(const String& outputName, const String& filterPath, const String& variableName) {
|
||||||
|
addParameter("-o" + outputName + ":" + filterPath + ":" + variableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TembooChoreo::setSettingsFileToWrite(const String& filePath) {
|
||||||
|
addParameter("-w" + filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TembooChoreo::setSettingsFileToRead(const String& filePath) {
|
||||||
|
addParameter("-r" + filePath);
|
||||||
|
}
|
||||||
|
|
44
hardware/arduino/avr/libraries/Temboo/Temboo.h
Normal file
44
hardware/arduino/avr/libraries/Temboo/Temboo.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# Temboo Arduino Yun library
|
||||||
|
#
|
||||||
|
# Copyright 2013, Temboo Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing,
|
||||||
|
# software distributed under the License is distributed on an
|
||||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||||
|
# either express or implied. See the License for the specific
|
||||||
|
# language governing permissions and limitations under the License.
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TEMBOO_H
|
||||||
|
#define _TEMBOO_H
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Process.h>
|
||||||
|
|
||||||
|
class TembooChoreo : public Process {
|
||||||
|
|
||||||
|
public:
|
||||||
|
void begin();
|
||||||
|
void setAccountName(const String& accountName);
|
||||||
|
void setAppKeyName(const String& appKeyName);
|
||||||
|
void setAppKey(const String& appKey);
|
||||||
|
void setChoreo(const String& choreo);
|
||||||
|
void setCredential(const String& credentialName);
|
||||||
|
void addInput(const String& inputName, const String& inputValue);
|
||||||
|
void addOutputFilter(const String& filterName, const String& filterPath, const String& variableName);
|
||||||
|
void setSettingsFileToWrite(const String& filePath);
|
||||||
|
void setSettingsFileToRead(const String& filePath);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
GetYahooWeatherReport
|
||||||
|
|
||||||
|
Demonstrates making a request to the Yahoo! Weather API using the Temboo Arduino Yun SDK.
|
||||||
|
|
||||||
|
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
||||||
|
|
||||||
|
A Temboo account and application key are necessary to run all Temboo examples.
|
||||||
|
If you don't already have one, you can register for a free Temboo account at
|
||||||
|
http://www.temboo.com
|
||||||
|
|
||||||
|
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
|
||||||
|
to the Internet.
|
||||||
|
|
||||||
|
Looking for another API? We've got over 100 in our Library!
|
||||||
|
|
||||||
|
This example code is in the public domain.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Bridge.h>
|
||||||
|
#include <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 save it once,
|
||||||
|
then just distribute 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
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user