Go Down

Topic: Weather LCD display via XML (Read 3 times) previous topic - next topic

kenneth87

Good day,

I'm starting a project on displaying the weather of the area i'm in (i.e. Sydney) on a LCD via an arduino uno with ethernet shield.

first, how do you get the xml code? i've seen some examples that links to google weather but the google weather link is not working?
appreciate it if someone could teach me how to get the xml code?

An example or sample code would be helpful too!

cheers!

Webmeister

You can use the Yahoo Weather API. I implemented a project in my book.
See my blog post regarding the stop of Google Weather
http://arduino-praxis.ch/2012/08/google-stoppt-weather-api/

I will post the code soon.

kenneth87

Thanks for the info mate. Looking forward to have a look at your code.

cheers!

kenneth87

Good day Webmeister,

Would you be kind to provide a sample code for the implementation of weather using yahoo's api?

Also if there's anyone that could help, i will appreciate it heaps!

Cheers!

Webmeister

To read the XML from Yahoo Weather API you can use the TextFinder library.

Before you read the weather data you need to get the ID (woeid) from your city.

Example: Zurich/Switzerland
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22Schweiz%20Z%C3%BCrich%22&format=xml

You will find the ID in the field <woeid>

Code to read the Yahoo Weather API

Code: [Select]

//
// Read Yahoo Weather API XML
// 03.09.2012
// http://arduino-praxis.ch


#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAD };
byte ip[] = { 10, 0, 1, 101 };
byte gateway[] = { 10, 0, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };

// Server Yahoo
IPAddress server(87,248,122,181);

EthernetClient client;
TextFinder  finder( client ); 

char place[50];
char hum[30];


void setup()
{
  // Start Ehternet
  Ethernet.begin(mac, ip);
  // Start Serial Port
  Serial.begin(9600);
  Serial.println("Setup...");
}


void loop()
{
  if (client.connect(server, 80))
  {
    // Call Wetter-API
    // w: ID from your City
    // http://weather.yahooapis.com/forecastrss?w=12893459&u=c
    ///
    Serial.println("Connect to Yahoo Weather...");
    client.println("GET /forecastrss?w=12893459&u=c HTTP/1.0");
    client.println("HOST:weather.yahooapis.com\n\n");
    client.println();
    Serial.println("Connected...");
  }
  else
  {
    Serial.println(" connection failed");
  }


  if (client.connected())
  {
   
    // Humidity
   if ( (finder.getString("<yweather:atmosphere humidity=\"", "\"",hum,4)!=0) )
   {
     Serial.print("Humidity:  ");
     Serial.println(hum);
   }
   else
   {
     Serial.print("No Humidity Data");
   }
   
   
    // Place/City
    if ( (finder.getString("<title>Conditions for ", " ",place,50)!=0) )
    {
      Serial.print("City:  ");
      Serial.println(place);
    }
   
   
    // Temperature
    if(finder.find("temp=") )
    {
     int temperature = finder.getValue();
     Serial.print("Temp C:  ");
     Serial.println(temperature);
   }
   else
   {
     Serial.print("No Temperature Data");
   }
   
         
  // END XML
  }
  else
  {
    Serial.println("Disconnected");
  }

  client.stop();
  client.flush();
  delay(60000);
}




Go Up