Obtener datos de una web y meterlo en una variable. [solucionado]

Hola, estoy intentando conectarme remotamente a una web mediante el ethernet de arduino w5100, para obtener varios datos y guardarlos en variables, para después poder hacer diferentes cosas.
Os pongo un ejemplo.
Accedemos a http://www.pandorasoft.com/arduino/
esto nos devuelve:

PrimerapalSegundapal

esto es visto desde un navegador.
bueno, desde arduino, nos devuelve por el serial esto:

el código que utilizo es este:

/*
  Web client
 
 This sketch connects to a website (http://www.google.com)
 using an Arduino Wiznet Ethernet shield. 
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 18 Dec 2009
 by David A. Mellis
 
 */

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(82,165,139,80); // Google

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET http://www.pandorasoft.com/arduino/ HTTP/1.0");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      ;
  }
}

Aquí me quedo pillado, como puedo meter cada palabra en una variable?????
Variable1 = Primerapal;
Variable2 = Segundapal;
las palabras siempre tendran la misma longitud 10 caracteres.

He intentado meterla en un string para después buscar, pero no puedo hacerlo o no se....

he conseguido meter todos los datos recibidos en una variable.

este es el código:

/*
  Web client
 
 This sketch connects to a website (http://www.google.com)
 using an Arduino Wiznet Ethernet shield. 
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 18 Dec 2009
 by David A. Mellis
 
 */

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(82,165,139,80); // Google

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
String codigo;
void setup() {
  // start the serial library:
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET http://www.pandorasoft.com/arduino/ HTTP/1.0");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    codigo = codigo + c;
    //Serial.print(myPins[0]);
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    Serial.print(codigo); //// mostramos el código que hemos obtenido de la web.
    // do nothing forevermore:
    for(;;)
      ;
  }
}

la variable se llama código y la muestro al final.

ahora solo me queda que extraer del string codigo, las dos palabras y pasarla a la variable...

Estoy investigando, alguna ayudita???

Hola,

Nunca he usado la librería ethernet, pero viendo rápidamente el código... Si haces que tus variables tengan un string/carácter especial, te facilitas la vida... por ejemplo, que las variables siempre empiecen con "@","var", etc.
Cuando haces un char c = client.read();, pues no tienes más que ver si c=='@', y a partir de ahí meter todo lo que venga después en tu variable hasta que se lea un espacio.

Saludos

Igor R.

gracias igor, me ha servido tu ayuda, lo he resuelto de la siguiente manera.

os pongo el código y ya cada un lo adapta para su necesidad, simplemente lo he colocado al final cuando se cierra la conexión para ver los resultados.

/*
  Web client
 
 This sketch connects to a website (http://www.google.com)
 using an Arduino Wiznet Ethernet shield. 
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 18 Dec 2009
 by David A. Mellis
 
 */

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(82,165,139,80); // Google

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
String codigo;
void setup() {
  // start the serial library:
  Serial.begin(57600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET http://www.pandorasoft.com/arduino/index.php?var=100 HTTP/1.0");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    codigo = codigo + c; /// genero el string con el código completo
    //Serial.print(myPins[0]);
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    //Serial.print(codigo);
    
    int posicion1 = codigo.indexOf("<p1>"); /// en la web la primera palabra empieza por <p1> a partir de aquí esta la primera palabra
    int posicion2 = codigo.indexOf("<p2>");/// en la web la segunda palabra empieza por <p2> a partir de aquí esta la segunda palabra
    String palabra1 = codigo.substring ( posicion1 + 4, posicion1 + 14 ); // el +4 es porque <p1> no me vale y mostrare a partir de que termine ----- el + catorce es para contar hasta 10 dígitos que no va a contener mas de 10 dígitos
    String palabra2 = codigo.substring ( posicion2 + 4, posicion2 + 14 );
      Serial.println(posicion1); // muestra donde empieza la 1 posición
      Serial.println(posicion2); // muestra donde empieza la 2 posición
      Serial.println(palabra1); // ya tengo la primera palabra metida en la variable palabra1
      Serial.println(palabra2); // ya tengo la segunda palabra metida en la variable palabra2
    
    // do nothing forevermore:
    for(;;)
      ;
  }
}

os dejo una muestra de lo que sale por el monitor serial..

bueno, ya que esto esta terminado, necesito que solo se ejecute cuando pulsemos un botón.

ahora amigos necesito vuestra ayuda.

Lo he intentado de diferentes formas, creando una función, varias funciones, ejecutándolo dentro de un if (valor del botón), etc.. etc.. pero no funciona..

Necesito vuestra ayuda, alguna ocurrencia, alguna pista?????

Un saludo y gracias de antemano.

Hola gracias por tu trabajo me ayudo mucho en un proyecto y de lo que deces hacer con el botón yo te recomendaria que hagas una interrución arduno no soporta por software pero si por hardware, lo que hace la interrupción es que al detectar el pulso del botón interrupe tu programa y se va hasta la parte del codigo que es la interrupción, ejecuta ese codigo y al terminar se regresa a donde estava antes de la interrución, cada modelo de arduino tiene diferentes pines de interrupción buscalos y usalo, ojala y te sirva.