getting Ethernet WebClient to Constantly Pulling Data

Hi,

So I am building a larger network of Arduino Uno's / Network Shields. About 20 of them will constantly query a server I have (about every 1.5 seconds).

The server simply will output a small amount of data. either "0:" or "1:m:s" (where m = Minutes | s = seconds) and it will parse that data for minutes and seconds.

I can get the arduino to connect to the server and pull the data once during the loop with this code.

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


byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0,177 };
byte server[] = { 192,168,0,98}; 


Client client(server, 80);

void setup() {
  // start the Ethernet connection:
  Ethernet.begin(mac, ip);
  // start the serial library:
  Serial.begin(9600);
  Serial.println("t:");
  // give the Ethernet shield a second to initialize:
  delay(1000);
}





void loop()
{
 client.println("GET /client.php");
    client.println();
    char c = client.read();
    Serial.print(c);  
  
}

So they are not pulling a lot of data, but the issue is it only runs once, I need it to loop. keep querying that server over and over

Updated code

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


byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0,177 };
byte server[] = { 192,168,0,98}; 

int mytime = 0;

Client client(server, 80);

void setup() {
  // start the Ethernet connection:
  Ethernet.begin(mac, ip);
  // start the serial library:
  Serial.begin(9600);
  Serial.println("t:");
  // give the Ethernet shield a second to initialize:
  delay(1000);
}





void loop()
{
  while (mytime == 0){
    
    //Ethernet.begin(mac, ip);
    client.println("GET /client.php");
    client.println();
    char c = client.read();
    Serial.print(c);  
    delay(2000);
  }//While
  
}

That gets me this

t:
t:
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

I see a couple of problems initially. You need to do some checking to see if you got the connection, wait for the connection, wait for the response, etc. Take a look at the various tutorials out there and start from there. The code at Ethernet - Arduino Reference should be enough to get you started. The idea is to get a single working connection, then start looping on it.

You may have several problems. Sounds like you may have overlapping request to the server.The w5100 based ethernet shield is only setup for four connections, and your code apparently has nothing to close the current connection when the data is received. Below is some simple client test code for reference.

//zoomkat 11-13-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 }; // Arduino IP address
byte server[] = { 208, 104, 2, 86 }; // zoomkat's web site

Client client(server, 80);

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  Serial.println("starting simple arduino client test");
  Serial.println();

  delay(1000);

  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

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

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    Serial.println("==================================");
    Serial.println("");
    client.stop();
    for(;;); //stops loop for a single get request.
  }
}

My Code was so horrible.

I had one of my co-workers who is amazing at C look at it. he took care of everything, once this project is done, Ill post plenty of pictures / code.

The problem with that solution is that you still don't know how to do it.

The problem with that solution is that you still don't know how to do it.

Some what of a lame assumption. One can easily learn from code that works as opposed to trying to learn from broken code.

draythomp:
The problem with that solution is that you still don't know how to do it.

While this is true, I learned PHP by my self looking at other peoples code. I understand basic parts of C however the way he did it, using arrays It would of taken me a while to figure that out.

I think this overall project that we are working on, with 20+ Connected Arduino's will be pretty cool.