Let's Get Set Up
1Make sure you have a Temboo account. If you don't already have one, you can register for free.
2Make sure that you have the latest version of the Arduino IDE. You should also check that you have the newest version of the Temboo Library by checking the Arduino Library Manager
3Make sure that your Yún is connected to the Internet. Arduino has a helpful guide if you need assistance.
4When you open the IDE, check to make sure you have the right board selected by going to Tools > Boards > Arduino Yún.
Write the Sketch
Copy the sketch code below into your Arduino IDE. If you'd like to change the location that you're retrieving the weather forecast for, you can edit the ADDRESS_FOR_FORECAST
variable.
This code was auto-generated on our website using the Yahoo > Weather > GetWeatherByAddress Choreo.
/* GetYahooWeatherReport Demonstrates making a request to the Yahoo Weather API using the Temboo Arduino Yun library. This example code is in the public domain. */ #include <Bridge.h> #include <Temboo.h> #include "TembooAccount.h" // contains Temboo account information // 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 }
Create Your Header File
The sketch above references the TembooAccount.h
header file, which contains your Temboo account information.
If you are currently logged in, you'll see your account details in the code snippet below (otherwise you'll see placeholder values). Copy the code snippet below into a new tab in Arduino and call it TembooAccount.h
.
#define TEMBOO_ACCOUNT "ACCOUNT_NAME" // your Temboo account name #define TEMBOO_APP_KEY_NAME "APP_NAME" // your Temboo app key name #define TEMBOO_APP_KEY "APP_KEY" // your Temboo app key
With both files in place you are ready to upload the sketch and check the weather forecast. Umbrella and sunscreen sold separately.
Convert the sketch to work with the Yún Shield
If you're working with the Yún Shield paired with another Arduino board, you'll need to make some small changes to the Yún sketch above it so that it's compatible with the Arduino Yún Shield.
1First, change the include statement #include <Temboo.h>
to #include <TembooYunShield.h>
. Your include statements should look like this:
#include <Bridge.h> #include <TembooYunShield.h> #include "TembooAccount.h"
2Next, change the Temboo object name from TembooChoreo
to TembooYunShieldChoreo
. Your code should look like this:
TembooYunShieldChoreo GetWeatherByAddressChoreo;
3Now your code is ready to run on your Yún Shield!
What's Next?
Now that you've got something simple up and running, why not move on try making your board do something more advanced?
Need Help?
We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.