Help with simple web parsing, 10$ reward :)

Hi, I need this done ASAP whoever does it first and correctly will get 10$ via paypal…
I want to get current temperature for my city using rss feed and print ti via serial.println and later play with that integer…
I have used sample code from: http://www.adafruit.com/forums/viewtopic.php?f=31&t=27003
But I have deleted unnecessary LCD line codes…

Here is my code:

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



byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xE3, 0x0F };
byte ip[] = { 192,168,5,177 };  // remarked here just in case a DHCP server plays funny with Arduino's DHCP code - I'm looking at you, every Microsoft DHCP Server!

char serverName[] = "69.5.27.250";  //char serverName[] = "www.rssweather.com";

// Initialize the Ethernet client library
EthernetClient client;
//Setup TextFinder
TextFinder  finder( client );
//setup character strings, or "straings" if you're from south like me

int a; // temporary
int temperature = 1; //temporary


void setup() {
  // start serial comms for debugging
  Serial.begin(9600);
  Serial.println("START");
  Ethernet.begin(mac);
  delay(1000);

}


void loop()
{

    if (client.connect(serverName, 80)) {
    client.println("GET http://69.5.27.250/icao/LDSP/rss.php HTTP/1.0"); // rssweather.com RSS feed for Camp Udairi, Kuwait
    client.println();
    Serial.println("connected");
    delay(1000);  //1 second ot display the LCD message above
  } 
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");

  }

  if (client.connected()) {
        
      

         Serial.println("searching for temp");
        finder.find("<dd id=\"heatindex\" style=\"display: inline;\">"); 
        finder.find("</dd>");        //find Heat Index
        int temperature = finder.getValue(); 
      
        Serial.println(temperature);
        Serial.println(",");
      
        
    
  if (temperature >= 90)  
     a=1;
      else
  if (temperature >=80)
     a=2;
        else
  if (temperature >=70)
  a=3;
  
  //Here at the end is where we stop the client, flush the data, wait 6 seconds, flush the serial data, and then it starts all over again
  client.stop();
  client.flush();
  delay(6000);  
  Serial.flush();
   } 

}

But I cant get temperature displayed… Program stops around Serial.println(“searching for temp”);

Thanks for your help, baxxx

        finder.find("<dd id=\"heatindex\" style=\"display: inline;\">"); 

finder.find("");        //find Heat Index
        int temperature = finder.getValue();

You tell it to find past the and then get a value, even though the value occurs before that part. So you probably want to comment that finder line out.

Then you will probably have to deal with the fact that your value is HTML encoded (unless TextFinder handles this for you) and not going to “fit” into an integer.

Textfinder code that works.

//
// 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[] = { 192, 168, 1, 102 };
byte gateway[] = { 192, 168, 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); 
}

Code that is a little more complex.

// Include description files for other libraries used (if any)
#include <SPI.h>
#include <Ethernet.h>

// Define Constants
// Max string length may have to be adjusted depending on data to be extracted
#define MAX_STRING_LEN  20

// Setup vars
char tagStr[MAX_STRING_LEN] = "";
char dataStr[MAX_STRING_LEN] = "";
char tmpStr[MAX_STRING_LEN] = "";
char endTag[3] = {'<', '/', '\0'};
int len;

// Flags to differentiate XML tags from document elements (ie. data)
boolean tagFlag = false;
boolean dataFlag = false;

// Ethernet vars
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 };
byte server[] = { 140, 90, 113, 200 }; // www.weather.gov

// Start ethernet client
EthernetClient client;

void setup()
{
  Serial.begin(9600);
  Serial.println("Starting WebWx");
  Serial.println("connecting...");
  Ethernet.begin(mac, ip);
  delay(1000);

  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("GET /xml/current_obs/KRDU.xml HTTP/1.0");    
    client.println();
    delay(2000);
  } else {
    Serial.println("connection failed");
  }  
}

void loop() {

  // Read serial data in from web:
  while (client.available()) {
    serialEvent();
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("Disconnected");
    Serial.println("==================================");
    Serial.println("");
    client.stop();

    // Time until next update
    //Serial.println("Waiting");
    for (int t = 1; t <= 15; t++) {
      delay(60000); // 1 minute
    }

    if (client.connect(server, 80)) {
      //Serial.println("Reconnected");
      client.println("GET /xml/current_obs/KRDU.xml HTTP/1.0");    
      client.println();
      delay(2000);
    } else {
      Serial.println("Reconnect failed");
    }      
  }
}

// Process each char from web
void serialEvent() {

   // Read a char
	 char inChar = client.read();
   //Serial.print(".");
  
   if (inChar == '<') {
      addChar(inChar, tmpStr);
      tagFlag = true;
      dataFlag = false;

   } else if (inChar == '>') {
      addChar(inChar, tmpStr);

      if (tagFlag) {      
         strncpy(tagStr, tmpStr, strlen(tmpStr)+1);
      }

      // Clear tmp
      clearStr(tmpStr);

      tagFlag = false;
      dataFlag = true;      
      
   } else if (inChar != 10) {
      if (tagFlag) {
         // Add tag char to string
         addChar(inChar, tmpStr);

         // Check for </XML> end tag, ignore it
         if ( tagFlag && strcmp(tmpStr, endTag) == 0 ) {
            clearStr(tmpStr);
            tagFlag = false;
            dataFlag = false;
         }
      }
      
      if (dataFlag) {
         // Add data char to string
         addChar(inChar, dataStr);
      }
   }  
  
   // If a LF, process the line
   if (inChar == 10 ) {

/*
      Serial.print("tagStr: ");
      Serial.println(tagStr);
      Serial.print("dataStr: ");
      Serial.println(dataStr);
*/

      // Find specific tags and print data
      if (matchTag("<temp_f>")) {
	      Serial.print("Temp: ");
         Serial.print(dataStr);
      }
      if (matchTag("<relative_humidity>")) {
	      Serial.print(", Humidity: ");
         Serial.print(dataStr);
      }
      if (matchTag("<pressure_in>")) {
	      Serial.print(", Pressure: ");
         Serial.print(dataStr);
         Serial.println("");
      }

      // Clear all strings
      clearStr(tmpStr);
      clearStr(tagStr);
      clearStr(dataStr);

      // Clear Flags
      tagFlag = false;
      dataFlag = false;
   }
}

/////////////////////
// Other Functions //
/////////////////////

// Function to clear a string
void clearStr (char* str) {
   int len = strlen(str);
   for (int c = 0; c < len; c++) {
      str[c] = 0;
   }
}

//Function to add a char to a string and check its length
void addChar (char ch, char* str) {
   char *tagMsg  = "<TRUNCATED_TAG>";
   char *dataMsg = "-TRUNCATED_DATA-";

   // Check the max size of the string to make sure it doesn't grow too
   // big.  If string is beyond MAX_STRING_LEN assume it is unimportant
   // and replace it with a warning message.
   if (strlen(str) > MAX_STRING_LEN - 2) {
      if (tagFlag) {
         clearStr(tagStr);
         strcpy(tagStr,tagMsg);
      }
      if (dataFlag) {
         clearStr(dataStr);
         strcpy(dataStr,dataMsg);
      }

      // Clear the temp buffer and flags to stop current processing
      clearStr(tmpStr);
      tagFlag = false;
      dataFlag = false;

   } else {
      // Add char to string
      str[strlen(str)] = ch;
   }
}

// Function to check the current tag for a specific string
boolean matchTag (char* searchTag) {
   if ( strcmp(tagStr, searchTag) == 0 ) {
      return true;
   } else {
      return false;
   }
}

I thought that texfinder will try to find value betwheen 2 finder.find instances, isnt taht the case?
For example if my value is in

My value

tags
I would need to use :
finder.find("

");
finder.find("/h1");
finder.getValue();

??

zooomkat thatnks for code send me your pp email adress to pm

BAXX: I thought that texfinder will try to find value betwheen 2 finder.find instances, isnt taht the case?

That's not what the documentation says. It seeks up to whatever the last find() call was and then captures the next numeric value. It doesn't say anything about getting values "between" anything.

Which, again, may be an issue because the webpage you're accessing doesn't send the temperature as a simple numeric value.