source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/GetYahooWeatherReport.ino @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 4 years ago

First release to Xenial

File size: 4.2 KB
Line 
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
27String ADDRESS_FOR_FORECAST = "104 Franklin St., New York NY 10013";
28
29int numRuns = 1;   // execution count, so that this doesn't run forever
30int maxRuns = 10;  // max number of times the Yahoo WeatherByAddress Choreo should be run
31
32
33void 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
43void 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*/
Note: See TracBrowser for help on using the repository browser.