Reconnecting to Ethernet

Hi guys,

I think my issue may be related to what's previously described in this forum post.

I have connected the ethernet board (not the PoE version) to my Arduino, along with a PIR sensor. So, as you may have surmised, I'm asking it to watch for motion and if it detects motion, request a script that I have out there on a server. This script then shoots me a text message letting me know that my sensor was tripped.

It detects motion reliably, but it only successfully fetches the php script that sends the text message the first time.

Could the failed subsequent connections be because it's holding open that original, successful HTTP connection open too long, preventing the arduino from reaching out again with subsequent GET requests for the script?

Here's my sketch:

//this comes directly matt williamson's work
#include <SPI.h>
#include <Ethernet.h>

// Declare Constants
const int sensorPin = 2;           // PIR Sensor is attached to digital pin 2
const int ledPin = 13;             // Built-in LED
const int ledBlinkTime = 500;      // Blink one for half a second while calibrating

// Wait for the seonsor to calibrate (20 - 60 seconds according to datasheet)
// 60 Seconds in milliseconds
const unsigned int calibrationTime = 60000;

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
char serverName[] = "example.com";

// 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() {
  Serial.begin(115200);
   
  pinMode(sensorPin, INPUT);
  pinMode(ledPin, OUTPUT);
    
  // We need to wait one minute for the sensor to calibrate
  // Get out of view of the sensor for this duration!
  
  // Blink the LED while calibrating
  for (unsigned int i=0; i<calibrationTime; i+=ledBlinkTime*2) {
    digitalWrite(ledPin, HIGH);
    Serial.println("Warming up... HIGH");
    Serial.println(i);
    delay(ledBlinkTime);
    Serial.println("Warming up... LOW");
    digitalWrite(ledPin, LOW);
    delay(ledBlinkTime);
  }
}

void loop() {
  // Constantly check the state of pin 2
  // If it is HIGH the sensor is detecting motion
  if (digitalRead(sensorPin) == HIGH) {
    // Turn the LED on
    digitalWrite(ledPin, HIGH);
    
          
         // 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:
          while(true);
        }
        
        // 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(serverName, 80)) {
          Serial.println("connected");
          client.println();
       
              Serial.println(" we detected motion, we're going to try to call the file which sends the SMS now");
            // Make a HTTP request:
      //    client.println("GET / HTTP/1.0"); original line
         client.println("GET /sms-script.php HTTP/1.0"); 
         client.println("host:example.com");
          client.println();

              } 
        else {
          // kf you didn't get a connection to the server:
          Serial.println("connection failed");
        }
    
        // Sleep for a second to prevent flooding the serial
    delay(5000);
  } else {
    // Turn the LED off
    digitalWrite(ledPin, LOW);
         
    Serial.println(" we DIDN'T detect motion!");
    delay(2000);
  }
}

I'm quite new to Arduino (and enjoying it!) so if I've made any silly beginner mistakes, be gentle with me!