1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-04 15:24:12 +01:00
Arduino/libraries/Bridge/examples/Temboo/GetYahooWeatherReport/GetYahooWeatherReport.ino

116 lines
4.2 KiB
Arduino
Raw Normal View History

2013-06-26 17:29:57 +02:00
/*
GetYahooWeatherReport
2014-04-03 19:56:46 +02:00
2014-05-30 12:17:09 +02:00
Demonstrates making a request to the Yahoo! Weather API using Temboo from an Arduino Yún.
2013-06-28 11:08:56 +02:00
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
2014-04-03 19:56:46 +02:00
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
2013-06-26 17:29:57 +02:00
http://www.temboo.com
2014-04-03 19:56:46 +02:00
2014-05-30 12:17:09 +02:00
This example assumes basic familiarity with Arduino sketches, and that your Yún is connected
2013-06-28 11:08:56 +02:00
to the Internet.
2014-05-30 12:17:09 +02:00
Looking for another API to use with your Arduino Yún? We've got over 100 in our Library!
2014-04-03 19:56:46 +02:00
2013-06-26 17:29:57 +02:00
This example code is in the public domain.
*/
#include <Bridge.h>
2013-07-08 15:09:09 +02:00
#include <Temboo.h>
2013-06-28 11:08:56 +02:00
#include "TembooAccount.h" // contains Temboo account information
2014-04-03 19:56:46 +02:00
// as described in the footer comment below
2013-06-26 17:29:57 +02:00
2013-07-03 09:02:59 +02:00
// the address for which a weather forecast will be retrieved
String ADDRESS_FOR_FORECAST = "104 Franklin St., New York NY 10013";
2013-07-08 15:09:09 +02:00
int numRuns = 1; // execution count, so that this doesn't run forever
2013-06-26 17:29:57 +02:00
int maxRuns = 10; // max number of times the Yahoo WeatherByAddress Choreo should be run
2013-07-08 15:09:09 +02:00
2013-06-26 17:29:57 +02:00
void setup() {
Serial.begin(9600);
2014-04-03 19:56:46 +02:00
2013-06-26 17:29:57 +02:00
// for debugging, wait until a serial console is connected
2013-07-03 09:02:59 +02:00
delay(4000);
2014-04-03 19:56:46 +02:00
while(!Serial);
2013-06-26 17:29:57 +02:00
Bridge.begin();
2013-07-08 15:09:09 +02:00
2013-06-26 17:29:57 +02:00
}
void loop()
{
// while we haven't reached the max number of runs...
2013-07-08 15:09:09 +02:00
if (numRuns <= maxRuns) {
2014-04-03 19:56:46 +02:00
2013-06-26 17:29:57 +02:00
// print status
2013-06-28 11:08:56 +02:00
Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "...");
2013-06-26 17:29:57 +02:00
2013-07-08 15:09:09 +02:00
// create a TembooChoreo object to send a Choreo request to Temboo
TembooChoreo GetWeatherByAddressChoreo;
2014-04-03 19:56:46 +02:00
2013-06-26 17:29:57 +02:00
// invoke the Temboo client
2013-07-08 15:09:09 +02:00
GetWeatherByAddressChoreo.begin();
// add your temboo account info
GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT);
GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY);
2014-04-03 19:56:46 +02:00
2013-07-08 15:09:09 +02:00
// set the name of the choreo we want to run
GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress");
2014-04-03 19:56:46 +02:00
2013-06-26 17:29:57 +02:00
// set choreo inputs; in this case, the address for which to retrieve weather data
// the Temboo client provides standardized calls to 100+ cloud APIs
2013-07-08 15:09:09 +02:00
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");
2014-04-03 19:56:46 +02:00
2013-07-08 15:09:09 +02:00
// 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");
2014-04-03 19:56:46 +02:00
// run the choreo
2013-06-26 17:29:57 +02:00
GetWeatherByAddressChoreo.run();
2014-04-03 19:56:46 +02:00
2013-06-26 17:29:57 +02:00
// when the choreo results are available, print them to the serial monitor
2014-04-03 19:56:46 +02:00
while(GetWeatherByAddressChoreo.available()) {
char c = GetWeatherByAddressChoreo.read();
2013-07-03 09:02:59 +02:00
Serial.print(c);
2013-06-26 17:29:57 +02:00
}
GetWeatherByAddressChoreo.close();
}
2013-07-03 09:02:59 +02:00
Serial.println("Waiting...");
2013-06-28 11:08:56 +02:00
Serial.println("");
2013-07-03 09:02:59 +02:00
delay(30000); // wait 30 seconds between GetWeatherByAddress calls
2013-06-26 17:29:57 +02:00
}
/*
IMPORTANT NOTE: TembooAccount.h:
2013-07-03 09:02:59 +02:00
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:
2013-06-26 17:29:57 +02:00
2014-04-03 19:56:46 +02:00
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
2013-06-26 17:29:57 +02:00
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
2014-04-03 19:56:46 +02:00
You can find your Temboo App Key information on the Temboo website,
2013-06-28 11:08:56 +02:00
under My Account > Application Keys
2013-06-26 17:29:57 +02:00
2013-07-03 09:02:59 +02:00
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
2014-04-03 19:56:46 +02:00
Keeping your account information in a separate file means you can share the main .ino file without worrying
2013-07-09 20:07:54 +02:00
that you forgot to delete your credentials.
2013-06-26 17:29:57 +02:00
*/