     resetEthernet(A5);
     delay(2000);
     Serial.println(F("apollo update Initialized"));
-    
+
     // Init SD Card
     // initialize the SD card
     card.begin(CHIP_SELECT, SPI_HALF_SPEED);
-  
+
     // initialize a FAT16 volume
     Fat16::init(&card);
 


bool checkBytes(char* bytes, char (*stream)()) {
  int byteCount = 0;
  while(matchingBytes < 4) {
    matchingBytes = bytes[matchingBytes] == stream() ? matchingBytes + 1 : 0;
    byteCount++;
    if (byteCount >= 2048) {

    const char name[] = "FIRMWARE.BIN";
    file.open(name, O_CREAT | O_WRITE);

    Serial.println(F("Getting new Firmware file"));
    if (client.connect(updateServer, 80)) {  //starts client connection, checks for connection
      Serial.println(F("Connected to Update Server"));
      client.println(F("GET /apollo/FIRMWARE.BIN HTTP/1.1")); //download text
      client.println(F("Host: www.debcal.co.za"));
      client.println(F("Connection: close"));  //close 1.1 persistent connection
      client.println(); //end of get request

      // Wait for http reponse and remove header
      Serial.println(F("waiting for data"));
      while (client.connected()) {
        while (client.available()) {
          if (checkBytes(crnl, byteStream)) {
            goto end;
          }
        }
      }
end:

      Serial.println(F("done waiting for data"));
      Serial.println();
      Serial.print(F("Prepended Value = "));

      int prependedSize = twoBytes();
      byte checkSum1 = client.read();
      byte checkSum2 = client.read();

      Serial.print(prependedSize);
      Serial.println(F(" bytes"));
      Serial.print(F("Prepended Sum1 = "));
      Serial.println(checkSum1);
      Serial.print(F("Prepended Sum2 = "));
      Serial.println(checkSum2);
      Serial.print(F("Data: "));
      int i = 0;
      byte sum1 = 0;
      byte sum2 = 0;

      while (client.connected()) {
        while (client.available()) {
          byte e = client.read();

          if (i == 0) {
            Serial.print(F("0% "));
          }
          if (i % (prependedSize / 64) == 0) {
            Serial.print(F("."));
          }
          if (i == prependedSize - 1) {
            Serial.print(F(" 100%"));
          }

          file.write(e);
          sum1 = (sum1 + e) % 255;
          sum2 = (sum2 + sum1) % 255;
          i++;
        }
      }
      Serial.println();
      Serial.print("Sum1 = ");
      Serial.print(sum1);
      Serial.print("; Sum2 = ");
      Serial.println(sum2);

      file.close();
      Serial.println();
      Serial.print(i);
      Serial.println(F(" Bytes Received."));
      if (prependedSize <= 0 || prependedSize != i || checkSum1 != sum1 || checkSum2 != sum2) {
        Serial.println(F("ERROR RECEIVING FIRMWARE!"));
      }
      else {
        Serial.println(F("SUCCESS!"));
      }
      if (!client.connected()) {
        Serial.println(F("Disconecting from update server"));
        client.stop();
      }

      //Disable the SD card:
      pinMode(CHIP_SELECT, OUTPUT);
      digitalWrite(CHIP_SELECT, HIGH);

      if (i > 4096) {
        Serial.println(F("Resetting..."));
        delay(200);
        resetFunc();
      }
    }
    else {
      Serial.println(F("connection failed")); //error message if no client connect
      Serial.println();
      Serial.println(F("Resetting..."));
      delay(200);
      resetFunc();
    }
  }
}


/**
   setupWDT sets up the watchdog timer bits and scaler to execute every 8s.
*/
void setupWDT()
{
  // Clear the reset flag.
  MCUSR &= ~(1 << WDRF);

  // In order to change WDE or the prescaler, we need to
  // set WDCE (This will allow updates for 4 clock cycles).
  WDTCSR |= (1 << WDCE) | (1 << WDE);

  // Set new watchdog timeout prescaler value
  // 8.0 seconds
  WDTCSR = 1 << WDP0 | 1 << WDP3;

  // Enable the WD interrupt.
  WDTCSR |= _BV(WDIE);
}


/**
    The WDT_vect routine is called by the WDT interrupt.
    The Arduino will be reset once the update interval has been exceeded.

*/
ISR(WDT_vect)
{
  updateCounter++;
  if (updateCounter * 8 / 15 >= updateInterval)
  {
    updateNow = true;
  }
  // Quick Lock up watch Dawg.
  else if (updateCounter * 8 / 60 >= updateInterval)
  {
    resetFunc();
  }
}

/**
   resetEthernet reset the ethernet controller.
   @param pin is to be directly connected to the reset pin on the ethernet shield.
*/
void resetEthernet(int pin) {
  pinMode(pin, OUTPUT);
  digitalWrite(pin, LOW);
