Uno + Ethernet Shield to PHP

@SurferTim,

This is modified version of your code(http://www.arduino.cc/playground/Code/WebClient)

It works like a charm but I am still not sure if it is still stable. I mean your part of code is great, but what I did might be changed the stability.

What do you think?

/*
Web client sketch for IDE v1.0.1 and w5100/w5200
Posted October 2012 by SurferTim
*/

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

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
//IPAddress ip(192,168,1,12);
//IPAddress gateway(192, 168, 1, 12);
//IPAddress subnet(255, 255, 255, 0);

IPAddress server(192,168,1,12); // Google
EthernetClient client;

int totalCount = 0;
int loopCount = 0;
char pageAdd[32];
TextFinder finder( client );
void setup() {
Serial.begin(9600);

pinMode(4,OUTPUT);
digitalWrite(4,HIGH);

Ethernet.begin(mac);
delay(2000);
Serial.println("Ready");
}

void loop()
{
if(loopCount < 10)
{
delay(10);
}
else
{
loopCount = 0;
sprintf(pageAdd,"/data.php",totalCount);
if(!getPage(server,pageAdd)) Serial.print("Fail ");
else Serial.print("Pass ");
totalCount++;
Serial.println(totalCount,DEC);
}

loopCount++;
}

byte getPage(IPAddress ipBuf,char *page)
{
int inChar;
char outBuf[128];

Serial.print("connecting...");

if(client.connect(ipBuf,80))
{
Serial.println("connected");

sprintf(outBuf,"GET %s HTTP/1.0\r\n\r\n",page);
client.write(outBuf);
}
else
{
Serial.println("failed");
return 0;
}

int connectLoop = 0;

while(client.connected())
{
while(client.available())
{
// inChar = client.read();
// Serial.write(inChar);
finder.find("<");
long speed_1 = finder.getValue();
Serial.print("Speed 1:");
Serial.print(speed_1); // end get first user speed
Serial.println("");

client.flush();
client.stop();
/* finder.find("<");
long speed_1 = finder.getValue();
Serial.print("Speed 1:");
Serial.print(speed_1); // end get first user speed
Serial.println("");/
connectLoop = 0;
}
/
if (client.available()) {
// char c = client.read();
// Serial.print(c);
// Serial.println("b");

finder.find("<"); // seek to the Results field
long value = finder.getValue(); // get numeric value
Serial.print(value);
Serial.println("");
client.flush();
client.stop();
}*/
connectLoop++;
if(connectLoop > 10000)
{
Serial.println();
Serial.println("Timeout");
client.stop();
}
delay(1);
}

Serial.println();

Serial.println("disconnecting.");
client.stop();

return 1;
}

What does this connectLoop do by the way? It is just for testing i suppose, right?

connectLoop++;
    if(connectLoop > 100)
    {
      Serial.println();
      Serial.println("Timeout");
      client.stop();
    }

...and here is the serial print:

Pass 1431
connecting...connected
Speed 1:706

disconnecting.
Pass 1432
connecting...connected
Speed 1:706

disconnecting.
Pass 1433
connecting...connected
Speed 1:706

disconnecting.
Pass 1434
connecting...connected
Speed 1:706

disconnecting.
Pass 1435
connecting...connected
Speed 1:706

disconnecting.

Thank you in advance