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?
Thanks for this code, it was super helpful. Does anyone know how to read in the forecasted temperature, not just the current? I modified the code above to search for "High" or even "Forecast" which seems to appear in the raw RSS feed, but it doesnt return anything. In fact finder.getvalue() doesn't return anything after the "Current Conditions", to me indicating that somehow the the forecast isn't part of the RSS link in the code above (even thought it appears when you look at the RSS in a browser). I'm trying to get the forcasted High and Low and the chance of rain as a number (although that doesn't appear in the RSS so I might have to look elsewhere). Any help would be immensely appreciated.
THanks for the response. My goal is to use the code to find the high and low temps (and eventually chance of rain) and then change the color of some LEDs depending on the range. I've left the LED part out until I can figure out how to read in the right information.
I've tried searching for "High", "Low", "Forecast", which all appear (at least to me) in the source RSS feed. If I search for "Current Conditions" that does work.
Here is my code:
//Source:
// Read Yahoo Weather API XML
// 03.09.2012
// http://arduino-praxis.ch
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x73, 0xC5 };
//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);
// Start Serial Port
Serial.begin(9600);
Serial.println("Setup...");
}
void loop()
{
if (client.connect(server, 80))
{
// Call Wetter-API
// w: ID from your City
// Alternate access
// 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("GET /forecastrss/60660_f.xml HTTP/1.0"); //I read on another forum that this link might provide more data
client.println("HOST:xml.weather.yahoo.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);
}
// High Temperature
// if(finder.find("temp=") ) original
if(finder.find("Forecast:") )
{
long temperature = finder.getValue();
Serial.print("High Temp F: ");
Serial.println(temperature);
}
else
{
Serial.print("No Temperature Data");
}
// Low Temperature
// if(finder.find("temp=") ) original
if(finder.find("Low") )
{
long temperature = finder.getValue();
Serial.print("Low Temp F: ");
Serial.println(temperature);
}
else
{
Serial.print("No Temperature Data");
}
// END XML
}
else
{
Serial.println("Disconnected");
}
client.stop();
client.flush();
delay(60000);
}
Thanks. Yes I can get Current Conditions to print, but not anything after that. Using your same code for instance and changing Current Conditions for Forecast won't print the Forecast, which is immediately following Current Conditions in the xml code. I'm also interested just in the number of HIgh and Low, not all the text bit (so that I can easily apply an if statement for a number range). Any ideas on why your code or the finder.getvalue() wont work for the Forecasted High and Lows.
Therefore it isn't possible to retrieve a value for HIGH by using finder.getValue()
It needs a more complex function to read the single values.
In this case I would use a PHP-Script which reads the data and puts them in a simple xml stream. In the second step you can use your Arduino board to read the output of the xml stream and display them in the serial monitor or on a display.
Hello all,
This is my first arduino project, and I've modified the script above to output my local temperature as a voltage that I can send to another system. Any insight as to why I'm not reading any output from pin 3 with this script?:
Figured it out!
I was getting a false on client.connect, which pointed me toward ethernet.begin
One of the network guys at my workplace noticed that it was looking for the wrong gateway, as mine ends in 254
I therefore had to enter both the dns server and gateway into the ethernet.begin command, and it worked!
Thanks for telling me about serial.print()! I'm new and didn't know I could do that!
-Matt