Ethernet XML (find)

Olá,

Estou a tentar obter a temperatura (e mais tarde outras informações) do site Weather Underground

Basicamente tenho a informação toda em XML e tento procurar a variável que pretendo mas o resultado é sempre negativo, nunca a encontra.

Exemplo de código obtido:

<response>
<version>0.1</version>
<termsofService>
http://www.wunderground.com/weather/api/d/terms.html
</termsofService>
<features>
<feature>conditions</feature>
</features>
<current_observation>
<image>
<url>
http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png
</url>
<title>Weather Underground</title>
<link>http://www.wunderground.com</link>
</image>
<display_location>
<full>Rome, Italy</full>
<city>Rome</city>
<state/>
<state_name>Italy</state_name>
<country>IY</country>
<country_iso3166>IT</country_iso3166>
<zip>00000</zip>
<magic>1</magic>
<wmo>16240</wmo>
<latitude>41.90000153</latitude>
<longitude>12.47999954</longitude>
<elevation>95.00000000</elevation>
</display_location>
<observation_location>
<full>
Roma Ardeatina - Appia Antica Caffarella, Rome, Lazio
</full>
<city>Roma Ardeatina - Appia Antica Caffarella, Rome</city>
<state>Lazio</state>
<country>Italy</country>
<country_iso3166>IT</country_iso3166>
<latitude>41.863281</latitude>
<longitude>12.502114</longitude>
<elevation>140 ft</elevation>
</observation_location>
<estimated></estimated>
<station_id>IROMAROM3</station_id>
<observation_time>Last Updated on March 7, 2:09 AM CET</observation_time>
<observation_time_rfc822>Fri, 07 Mar 2014 02:09:21 +0100</observation_time_rfc822>
<observation_epoch>1394154561</observation_epoch>
<local_time_rfc822>Fri, 07 Mar 2014 02:09:22 +0100</local_time_rfc822>
<local_epoch>1394154562</local_epoch>
<local_tz_short>CET</local_tz_short>
<local_tz_long>Europe/Rome</local_tz_long>
<local_tz_offset>+0100</local_tz_offset>
<weather>Clear</weather>
<temperature_string>47.3 F (8.5 C)</temperature_string>
<temp_f>47.3</temp_f>
<temp_c>8.5</temp_c>
<relative_humidity>36%</relative_humidity>
<wind_string>Calm</wind_string>
<wind_dir>North</wind_dir>
<wind_degrees>0</wind_degrees>
<wind_mph>0.0</wind_mph>
<wind_gust_mph>0</wind_gust_mph>
<wind_kph>0.0</wind_kph>
<wind_gust_kph>0</wind_gust_kph>
<pressure_mb>1017</pressure_mb>
<pressure_in>30.04</pressure_in>
<pressure_trend>+</pressure_trend>
<dewpoint_string>22 F (-6 C)</dewpoint_string>
<dewpoint_f>22</dewpoint_f>
<dewpoint_c>-6</dewpoint_c>
<heat_index_string>NA</heat_index_string>
<heat_index_f>NA</heat_index_f>
<heat_index_c>NA</heat_index_c>
<windchill_string>47 F (8 C)</windchill_string>
<windchill_f>47</windchill_f>
<windchill_c>8</windchill_c>
<feelslike_string>47 F (8 C)</feelslike_string>
<feelslike_f>47</feelslike_f>
<feelslike_c>8</feelslike_c>
<visibility_mi>N/A</visibility_mi>
<visibility_km>N/A</visibility_km>
<solarradiation>0</solarradiation>
<UV>-1</UV>
<precip_1hr_string>0.00 in ( 0 mm)</precip_1hr_string>
<precip_1hr_in>0.00</precip_1hr_in>
<precip_1hr_metric>0</precip_1hr_metric>
<precip_today_string>0.00 in (0 mm)</precip_today_string>
<precip_today_in>0.00</precip_today_in>
<precip_today_metric>0</precip_today_metric>
<icon>clear</icon>
<icon_url>http://icons-ak.wxug.com/i/c/k/nt_clear.gif</icon_url>
<forecast_url>
http://www.wunderground.com/global/stations/16240.html
</forecast_url>
<history_url>
http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IROMAROM3
</history_url>
<ob_url>
http://www.wunderground.com/cgi-bin/findweather/getForecast?query=41.863281,12.502114
</ob_url>
</current_observation>
</response>

No Arduino estou a usar o seguinte:

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char serverName[] = "api.wunderground.com";
EthernetClient client;

void setup()
{
  Serial.begin(9600);
  if(Ethernet.begin(mac) == 0) { 
    Serial.println("Failed to configure Ethernet using DHCP");  
    while(true)   // no point in carrying on, so stay in endless loop:
      ;
  }
  delay(1000); // give the Ethernet shield a second to initialize

  Serial.println("connecting...");
}

void loop()
{
  if (client.connect(serverName,80)>0) {

    client.println("GET /api/MyKey/conditions/q/Italy/rome.xml HTTP/1.0");  
    client.println();
  }
  else {
    Serial.println(" connection failed");
  }
  if (client.connected()) {
     if(client.find("<temp_c>") )
     {
        int temperature = client.parseInt();
        Serial.print("Temperature is ");  
        Serial.println(temperature);
     }
    else
      Serial.println("Could not find temperature field");
     if(client.find("<relative_humidity>") )      
     {
        int humidity = client.parseInt(); 
        Serial.print("Humidity is ");  
        Serial.println(humidity); 
     }
     else
       Serial.println("Could not find humidity field");
  }
  else {
    Serial.println("Disconnected");
  }
  client.stop();
  client.flush();
  delay(60000); // wait a minute before next update
}

Basicamente queria ver o valor de **temp_**c e relative_humidity, consegue conectar-se ao site mas depois devolve o erro de que não as encontra. Estou a fazer algo de errado?

Quem dera se fosse tão simples.. Primeiro você tem que ler caracter por caracter, para depois manipular.

Segue um método que fiz, baseados em exemplos da net, o clienteIP é o seu client

// tamanho do buffer HTTP, seu caso deverá ser bem maior, pois o xml é grande
#define REQ_BUF_SZ   70
char HTTP_req[REQ_BUF_SZ] = {0}; //buffered HTTP request stored as null terminated string
char req_index = 0;              // index into HTTP_req buffer

void getServerData() {
    int numT=0;
    //esperar dados servidor
    while((!clientIP.connected() || !clientIP.available()) && numT<15000) {
      delay(1); 
      numT++;
    }
    Serial.println();
    
    numT=0;
    while ((clientIP.connected() || clientIP.available()) && numT<1000) {
      char c = clientIP.read();
      if (req_index >= (REQ_BUF_SZ - 1)) req_index=0;
      if (req_index < (REQ_BUF_SZ - 1)) {
          HTTP_req[req_index] = c;          // save HTTP request character
          req_index++;
      }       
      Serial.print(c);
      numT++;
    }
    
    Serial.println(F("FIM"));
    
    Serial.println(F("Desconectando"));
    clientIP.stop();      
}

depois para verificar os valores pode user o seguinte código

if (StrContains(HTTP_req, "<tag_xml>")) {
  //ler o buffer e encontrar a variável.. Você pode criar um método baseado no abaixo para fazer isso.
}

char StrContains(char *str, char *sfind)
{
    char found = 0;
    char index = 0;
    char len;

    len = strlen(str);
    
    if (strlen(sfind) > len) {
        return 0;
    }   
    
    while (index < len) {        
        if (str[index] == sfind[found]) {
            found++;
            if (strlen(sfind) == found) {
                return 1;
            }
        }
        else {
            found = 0;
        }
        index++;
    }
    return 0;
}

Espero que isso te ajude.

Parecido com o seu:
http://forum.arduino.cc/index.php/topic,39023.0.html