Ethernet Shield with Webpage on SD Card not working anymore

Hi All!

I am running an UNO with an Ethernet Shield since a couple of weeks without any issues.
I have a webpage (only one index.htm) on the SD Card for AJAX in and output.

Yesterday I wanted to change the index.htm and since then the SD-Card is not working anymore.

Also when I reverted back to the original code, it was not working anymore. Whenever I try a code, where the webpage is generated via the Arduino Code it is working, but when the code is coming from SD then I am getting only a row of special characters on the webpage:

<ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ... this is continuning until I stop the webclient.

If I just but a “Hello World” on the SD-Card, I have the same result.

Arduino Main and Setup:

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
// size of buffer used to capture HTTP requests
#define REQ_BUF_SZ   60

const int maintButton = 8; // Maintenance Button to but Smoke Detectors in Detection Mode
const int maintLED = 6; // Show Detection Mode with LED 
const int checkDetector = 7; // Set Relay to closed mode to but Smoke Detecorts into Detection Mode
const int alertLED = 5; // Show Alarm with LED
const int statusLED = 3; // Show Operational Mode with LED
const int alertDetector = 9; // Checking 2-wire of Smoke Detectors for 5Volt Alarm Signal

long lastMillis = 0;
long currentMillis = 0;
long previousMillis = 0;
long blinkMillis = 0;
long blinkInterval = 1000;

int buttonState = 0;
int alertState = 0;
int maintenanceState = 0;
int emailState = 0;

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip( 192, 168, 1, 111 );    
IPAddress gateway( 192, 168, 1, 1 );
IPAddress subnet( 255, 255, 255, 0 );

IPAddress smtp( 192, 168, 2, 2 );

EthernetServer server(80);  // create a server at port 80
File webFile;               // the web page file on the SD card
char HTTP_req[REQ_BUF_SZ] = {
  0}; // buffered HTTP request stored as null terminated string
char req_index = 0;              // index into HTTP_req buffer

EthernetClient client;

void setup()
  pinMode (checkDetector,OUTPUT);
  pinMode (maintButton,INPUT);
  pinMode (maintLED,OUTPUT);
  pinMode (alertLED,OUTPUT);
  pinMode (statusLED,OUTPUT);
  pinMode (alertDetector,INPUT);
  digitalWrite (checkDetector,HIGH); 

  // disable Ethernet chip
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);

  Serial.begin(9600);       // for debugging

  // initialize SD card
  Serial.println(F("Initializing SD card..."));
  if (!SD.begin(4)) {
    Serial.println(F("ERROR - SD card initialization failed!"));
    return;    // init failed
  Serial.println(F("SUCCESS - SD card initialized."));
  // check for index2.htm file
  if (!SD.exists("index5.htm")) {
    Serial.println(F("ERROR - Can't find index5.htm file!"));
    return;  // can't find index file
  Serial.println(F("SUCCESS - Found index5.htm file."));

  Ethernet.begin(mac, ip, gateway, gateway, subnet);  // initialize Ethernet device
  server.begin();           // start to listen for clients


Arduino Loop (only parts):

void loop()
  EthernetClient client = server.available();  // try to get client

  currentMillis = millis();

  if (client) {  // got client?
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {   // client data available to read
        char c =; // read 1 byte (character) from client
        // limit the size of the stored received HTTP request
        // buffer first part of HTTP request in HTTP_req array (string)
        // leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
        if (req_index < (REQ_BUF_SZ - 1)) {
          HTTP_req[req_index] = c;          // save HTTP request character
        // last line of client request is blank and ends with \n
        // respond to client only after last line received
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println(F("HTTP/1.1 200 OK"));
          Serial.println(F("HTTP/1.1 200 OK"));
          // remainder of header follows below, depending on if
          // web page or XML page is requested
          // Ajax request - send XML file
          if (StrContains(HTTP_req, "ajax_inputs")) {
            // send rest of HTTP header
            client.println(F("Content-Type: text/xml"));
            client.println(F("Connection: keep-alive"));
            // send XML file containing input states
          else {  // web page request
            // send rest of HTTP header
            client.println(F("Content-Type: text/html"));
            client.println(F("Connection: keep-alive"));
            // send web page
            webFile ="index5.htm");        // open web page file
            Serial.println(F("open index.htm"));
            if (webFile) {
              while(webFile.available()) {
                client.write(; // send web page to client
              Serial.println(F("close webfile"));
          // display received HTTP request on serial port
          // reset buffer index and all buffer elements to 0
          req_index = 0;
          StrClear(HTTP_req, REQ_BUF_SZ);
        // every line of text received from the client ends with \r\n
        if (c == '\n') {
          // last character on line of received text
          // starting new line with next character read
          currentLineIsBlank = true;
        else if (c != '\r') {
          // a text character was received from client
          currentLineIsBlank = false;
      } // end if (client.available())
    } // end while (client.connected())
    delay(1);      // give the web browser time to receive the data
    client.stop(); // close the connection
  } // end if (client)

I can ping the ethernet shield and the code also notifies me, that the index.htm was found.
The SD-Card is ok, because I also tested a second Card.

Any ideas? Shield defective?


EDIT: In the Code I am accessing index5.htm and not index.htm, because I tried to copy/paste the file.

I do not know why, but it is working again... :astonished: