Search for word in a TCP string

sorry for my bad english I'm German.

My problem - I want to read a number from a website and display it on the arduino. Now, with the program, the entire page is displayed on the monitor. I need only these 3-4 points (in red), which may change. This is a partial output of the page. What should I include in the program so that only these numbers are displayed. The update should be about 1 minute.

Thank you for your efforts

PS. the server is password protected and has a 64base encoding. It should also work on normal websites.

#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
int inByte;

#define LOGIN ("Yta6dGVjdeCCG5paw==.") //Base64 coded USERNAME:PASSWORT
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(95,13,0,201); // Webserver
EthernetClient client;
TextFinder finder( client);
void setup() {
  Serial.begin(9600);      
   while (!Serial) {
    ; // wait for serial port
  }

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Ethernet-debug using DHCP");
    for(;;)
      ;
  }
  delay(1000);
  Serial.println("connecting, please wait");
  if (client.connect(server, 80)) {
    Serial.println("connected");
client.print(LOGIN);
client.println("GET  HTTP/1.0");
    client.println();
  } 
  else {
    Serial.println("faulty connection");
  }
}

void loop()
{
  if (client.available()) {
    inByte = client.read();
    Serial.print(char (inByte));
  if (!client.connected()) {
    Serial.println("disconnected");
    client.stop();
    for(;;)
      ;
  }
}
}

This is a partial output of the page

Sensor 4Pumpe VL12,5°C12,4 / 12,6 Sensor 5Brauchwasser12,9°C12,8 / 13,0 Sensor 6Nebengebaeude8,9°C8,8 / 9,2

Greeting
Gerd

void loop()
{
  if (client.available()) {
    inByte = client.read();
    Serial.print(char (inByte));

If you don't save the data in an array, you can forget all about parsing and extracting it.

This topic only comes up about twice a day. Hard to believe you couldn't find one of the bazillion other posts on the same topic.

Here is a simple example, maybe it will help you :slight_smile:

~~http://codepad.org/z5U6NwLe~~

http://codepad.org/GsJgSZqd

Given that the content of the page stays the same except different values, you could use:

finder.find("Pumpe VL");
finder.find("right\">);
value = finder.getValue();
finder.find(",");
afterpoint = finder.getValue();

After that you just have to build a float again from your two parts (because Germany uses the comma instead of the point you cannot use the getFloat() method).

What you need is simple pattern matching - you want to look for a '>' first, then any number of digits or '.' characters, then a '<'. Only if you get to a '<' without seeing an unwanted character should you print the match-so-far. In between matches you look for a '>' char to put you into the matching mode.

Alternatively you might want to recognise the string "<td" and count instances. You also recognise '>' characters and if the number of instances of "<td" has increased since the last '>' you saw, this should be a tag's body - you can collect characters for when the count is 3, 8, 13, 18 etc - thus picking out the right entries.

@PaulS,
Thanks for the note. I want to say in my defense that I have very much looked for the same topics, but they are not equal. Moreover, it is a little difficult for me to understand. I could not believe that I am so pissed off because I have re-adjusted something or did not find.

Thanks @ Guix,
I will try to use the hint, so maybe it works

Hallo @pylon,
warum kann ich nicht die getFloat() Methode nehmen, hat das denn was mit dem Land zu schaffen ?

Hello @ MarkT,
I have to understand first of all, can you give me an example string that fits for my script?

warum kann ich nicht die getFloat() Methode nehmen, hat das denn was mit dem Land zu schaffen ?

In a float (floating point number, the name explicitly states "point") the integer part is usually delimited from the fractional part by a point ("."). Germany uses the comma (",") but most simple parsers don't accept that as a valid character of a number, so does the TextFinder class. That means if your web page is displaying floats in the German format you have to do the parsing yourself or use the integer parsing method and reconstruct the float yourself.

Hello @pylon,
thanks for the tip, I didn`t know it.
Regards Gerd

Thank you again.
The Swiss have what it takes. Alias ??"pylon" was able to show me the right way. It runs great, the intricacies I will do it alone.
Thanks @ pylon
@ PaulsS, as you see, it goes without saving in an array. One should also look for simple ways.
All thank you very much

Greetings Gerd

The last script:

#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
int inByte;
int value;
int Zahl1;
int Zahl2;
#define LOGIN ("YWRdkW4c2FkVjaG56SSzw==.") //Base64 kodiert USERNAME:PASSWORT
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(95,33,3,26); // Webserver
EthernetClient client;
TextFinder finder( client);
void setup() {
  Serial.begin(9600);
   while (!Serial) {
    ; // warte bis serieller Port verbunden ist
  }

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Ethernet-Fehler using DHCP");
    for(;;)
      ;
  }
  delay(1000);
  Serial.println("verbinde, bitte warten...");
  if (client.connect(server, 80)) {
    Serial.println("verbunden");
client.print(LOGIN);
client.println("GET  HTTP/1.0");
    client.println();
    finder.find("Nebengebaeude");//kann beliebige Reihe sein
finder.find("right\">");
value = finder.getValue();
finder.find("<");// ist Zahl vor Komma
Zahl1 = finder.getValue();
finder.find(",");// ist Zahl hinter Komma
Zahl2 = finder.getValue();

Serial.print("die Temperatur = ");
Serial.print(Zahl1);
Serial.print(",");
Serial.print(Zahl2);
Serial.println(" Grad");
  } 
  else {
    Serial.println("Verbindung fehlerhaft");
  }
}

void loop()
{
  }

@ PaulsS, as you see, it goes without saving in an array. One should also look for simple ways.

You mean ways where someone else has done all the work. You might be surprised at the resources you are consuming using the TextFinder class to do the work. But, it's your project. If you have the resources to spare, fine. Don't come back whining about running out of memory, though.

Dear friend, I really need any more than this sole indicator. Important thing is that it works.

Greeting Gerd

Important thing is that it works.

Famous last words. I've heard this before. Let me guess what is coming next:
"I tried to merge this with another script, and it fails."

@PaulS and @SurferTim: In general I agree with you but in this case I cannot see why TextFinder should pose problems. It's quite slim, doesn't use the String class or other resource hogs. Also, I cannot find any potential problems, if one wants to merge a script with TextFinder with another one.

Did you notice the topic? Does TextFinder empty the rx buffer and wait for the server to close the connection? You are gonna need to add stuff. That will take memory, both program and SRAM. Like I said, I've heard this before.

Hello, I can report that it works fine for 3 hours ONLINE.
I added an LCD4884 display and fill it with a menu control for variable use of information

Greetings Gerd