Certo!
/*
* Yahoo01
* http://forum.arduino.cc/index.php?topic=121992.msg920175#msg920175
* To get the city ID
* Goto https://weather.yahoo.com and enter the city in the search bar
* You get someting like this
* https://weather.yahoo.com/italy/sicily/catania-713571/
* The ID is 713571
*
* Original code by Webmeister
* http://forum.arduino.cc/index.php?action=profile;u=15387
* Read Yahoo Weather API XML
* 03.09.2012
* http://arduino-praxis.ch
*
* Modifications
* 2015-10-14
* Added DHCP by zoomx
* Added Current Condition
* http://forum.arduino.cc/index.php?topic=121992.msg933688#msg933688
*
*/
#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);
IPAddress server(217, 12, 1, 156);
EthernetClient client;
TextFinder finder( client );
char place[50];
char hum[30];
char currentcond[50];
void setup()
{
// Start Serial Port
Serial.begin(9600);
Serial.println("Yahoo01");
Serial.println("Setup...");
// Start Ehternet
//Ethernet.begin(mac, ip);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for (;;)
;
}
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}
void loop()
{
if (client.connect(server, 80))
{
// Call Wetter-API
// w: ID from your City
// http://weather.yahooapis.com/forecastrss?w=713571&u=c
///
Serial.println("Connect to Yahoo Weather...");
client.println("GET /forecastrss?w=713571&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);
}
// Current Condition
//if ( (finder.getString("<b>Current Conditions:</b>
", "C
", currentcond, 50) != 0) )
if ( (finder.getString("text=\"", "\"", currentcond, 50) != 0) )
// <b>Current Conditions:</b>
// CHECK THIS ^^^^
{
Serial.print("Current Cond: ");
Serial.println(currentcond);
}
// Temperature
if (finder.find("temp=") )
{
int temperature = finder.getValue();
Serial.print("Temp C: ");
Serial.println(temperature);
}
else
{
Serial.print("No Temperature Data");
}
// Forecast doesn't work
if ( (finder.getString("
<b>Forecast:</b>
","
", currentcond, 50) != 0) )
{
Serial.print("Forecast: ");
Serial.println(currentcond);
}
// END XML
}
else
{
Serial.println("Disconnected");
}
client.stop();
client.flush();
delay(60000);
}
Fa uso della stessa libreria TextFinder.
Ho messo l'IP di Yahoo ma credo che se uso yahoo.it dovrebbe funzionare lo stesso.
Anche qui non arriva alle Current Condition mentre stampa ciò che c'è prima.