Pages: [1]   Go Down
Author Topic: TextFinder library for parsing Ethernet or Serial  (Read 2520 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Tesla Member
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A library named TextFinder has been added to the playground that enables  extracting information from a stream of data. It was created to be used with the Arduino Ethernet library to find particular fields and get strings or numeric values. I can also be used with Serial data.

To use TextFinder, you create an 'instance' for the stream you want to processes. For example, the following fragment is based on the Ethernet client example sketch distributed with Arduino. That sketch does a google search on the term arduino.  The following adds functionality to print the number of hits reported by google.

Add these lines  before setup:
  #include <TextFinder.h>
  TextFinder finder( client );

Modify the connection code as follows:
  if (client.connected())
    finder.find("Results <b>");  // seek to the Results field
    finder.find("of about <b>"); // skip past this
    long value = finder.getValue(); // get numeric value
    Serial.println(" hits");

The remainder of the sketch can be as in the distributed example. The find method reads data from the client until it finds the string: "Results <b>"
It then looks for the string: "of about <b>"
And the getValue method returns the next numeric value.

See the playground for more details:

Copenhagen / Denmark
Offline Offline
Edison Member
Karma: 6
Posts: 2360
Do it !
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That looks potentially very usefull.

Pages: [1]   Go Up
Jump to: