Ethernet Shield Issues

Hello,

I'm using the Arduino with an Ethernet Shield in order to poll a web server for PWM values to put through to particular pins. I'm setting it up so that the server passes its response as a byte from 0-255 to the Arduino from a GET request. The arduino can request any number of different responses and put them out to different pins. In the case of my code below, the arduino requests values for device 1 & 2 and puts those values out on pins 5 & 6. I have it working so that it gets the first value, but for some reason, when I set the polling time to 60 seconds, it doesn't poll again. When I change the polling interval to 30 seconds, it works as expected. I've removed the server information for the code below, but hopefully someone might know what's going on by looking at the code.

Thanks,
Matt

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 1, 177 };  //change for different local networks
byte server[] = { IP HERE }; //change for different servers
Client client(server, 80);

const int numOfDevices = 2;
int value[] = {0, 0}; //value to display on meter for each meter/device
const int device[] = {1, 2};  //device identifiers (on server)
const int meterPin[] = {5, 6}; //pins to associate with each device
int secondsDelay = 60;  //polling interval

void setup() {
 Serial.begin(9600);
 Ethernet.begin(mac, ip);
 delay(1000);
}

void loop() {
for (int i = 0; i < numOfDevices; i++) //iterate for each device
    {
     if (client.connect()) {
        client.print("GET /projects/pwm/?device=");
        client.println(device[i]);
        client.println();
        delay(1000);
     }
     else
       Serial.println("Connection failed.");
    do {
     if (client.available()) {
      Serial.println("Reading data from server...");
      value[i] = client.read();
      client.flush();
    }
    } while ( client.connected() );
    if (!client.connected()) {
      client.stop();
    } 
     analogWrite(meterPin[i], value[i]);
     Serial.println(value[i]); 
  } //end for each device
  
   delay(secondsDelay * 1000);
}
   delay(secondsDelay * 1000);

The secondsDelay variable is an int. When it contains 30, and is multiplied by 1000, the result is 30000, which still fits in an int. When it contains 60, and is multiplied by 1000, the result is 60000, which results in an overflow condition.

If you look at the reference documentation for delay, it says:

Syntax

delay(ms)

Parameters

ms: the number of milliseconds to pause (unsigned long)

Try changing the type of secondsDelay from int to unsigned long, and 1000 to 1000UL.

The multiplication, which really isn't necessary, will be performed using unsigned longs, and the result will fit in an unsigned long, without overflow.

That was it! Thank you so much for your help.