Project tutorial
Get local weather from Yahoo! with Temboo

Get local weather from Yahoo! with Temboo © GPL3+

Here we'll show how to make a request to the Yahoo! Weather API from your Arduino Yún. Then you'll be ready to build the weather vane for...

  • 1,281 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

About this project

1. Get Set Up

  1. Make sure you have a Temboo account. If you don't already have one, you can register for a free account here.
  2. Make sure that your Yún is connected to the Internet.

2. Write the Sketch

Copy the sketch code below into a new tab in your Arduino IDE. This code calls the GetWeatherByAddress Choreo, and you can edit the address value to be whatever you like.

/*
  GetYahooWeatherReport
  
  Demonstrates making a request to the Yahoo! Weather API using the Temboo Arduino Yun SDK.
  
  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
}

3. 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 into a new tab in Arduino and call it TembooAccount.h.

With both files in place you are ready to upload the sketch and check the weather forecast. Umbrella and sunscreen sold separately.

#define TEMBOO_ACCOUNT "accountName"  // your Temboo account name 
#define TEMBOO_APP_KEY_NAME "myFirstApp"  // your Temboo app key name
#define TEMBOO_APP_KEY  "abc123xxxxxxxxxxxxxx"  // your Temboo app key

4. What's Next?

Now that you know how the weather is looking, why not check out the other 2000+ Choreos in our Library and start thinking about all the possibilities for your next Yún project.

5. Need Help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.

Code

Code snippet #1Arduino
/*
  GetYahooWeatherReport
  
  Demonstrates making a request to the Yahoo! Weather API using the Temboo Arduino Yun SDK.
  
  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
}

Comments

Created by

Temboo_OFFICIAL

Are you Temboo_OFFICIAL? Claim this project and add it to your profile.

This is mine

Posted by

Arduino scuola
Arduino_Scuola
  • 32 projects
  • 97 followers

Published on

July 8, 2016

Members who respect this project

Default
See similar projects
you might like

Similar projects you might like

Upload a File to your Dropbox Account with Temboo

Project tutorial by Temboo_OFFICIAL

  • 1,187 views
  • 0 comments
  • 1 respect

Read And Update Databases With Temboo

Project tutorial by Temboo_OFFICIAL

  • 2,406 views
  • 2 comments
  • 5 respects

Send an SMS using Twilio with Temboo

Project tutorial by Temboo_OFFICIAL

  • 1,472 views
  • 1 comment
  • 1 respect

Send An Email From Your Gmail Account With Temboo

Project tutorial by Temboo_OFFICIAL

  • 1,383 views
  • 0 comments
  • 2 respects

Post Data to a Google Spreadsheet with Temboo

Project tutorial by Temboo_OFFICIAL

  • 1,217 views
  • 0 comments
  • 7 respects

Control your Yún from your Phone with Temboo

Project tutorial by Temboo_OFFICIAL

  • 915 views
  • 0 comments
  • 1 respect
Add projectSign up / Login