Sd_Open() function doesnt work properly

Sd_Open() function doesnt work properly but when im dislocate the function to near while(1) loop it works and i can see my html code on the internet. (Btw im trying to get speed of a motor and visulize on a grafiphical interface in internet.) Can u guys help me pls.


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

//------------------------------------------------
File myFile;
//----------------------------------------
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x4A, 0xE0 };
EthernetServer server(80);
boolean receiving = false;  //keep track if receiving data

//----------------------------------------
int freq = 0;
int pin;

// Pins
#define ENCA 3
#define ENCB 2
#define PWM 5
#define IN1 9
#define IN2 6

EthernetClient client;
//===================================================================

void setup() {


  Serial.begin(9600);
  pinMode(53, OUTPUT);
  Ethernet.init(10);
  pinMode(ENCA, INPUT);
  pinMode(ENCB, INPUT);
  pinMode(PWM, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);


  //-----------------------------------------------------
  Serial.println(F("Initializing SD card..."));
  if (!SD.begin(4)) {
    Serial.println(F("Initialization failed!"));
    return;
  }
  Serial.println(F("Initialization OK"));
  //-----------------------------------------------------
  if (!SD.exists("dhtajax.htm")) {
    Serial.println(F("dhtajax.htm not found!"));
    return;
  }
  Serial.println(F("dhtajax.htm found"));
  //-----------------------------------------------------

  if (!Ethernet.begin(mac))  //connect with DHCP
  {
    Serial.println("Could not Configure Ethernet with DHCP.");
    return;
  } else Serial.println("Ethernet Configured!");

  server.begin();
  Serial.print(F("Server Started...\nLocal IP: "));
  Serial.println(Ethernet.localIP());
  myFile = SD.open("deneme.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening deneme.txt");
  }
  myFile = SD.open("deneme.txt");
  if (myFile) {
    Serial.println("deneme.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening deneme.txt");
    myFile.close();
  }
  open_me();
  open_me();
  open_me();
  open_me();
  while (1) {
    delay(100);
    
    String HTTP_req;
    client = server.available();
    //---------------------------------------------------------------------------
    if (client) {
      //HTTP request ends with a blank line
      boolean currentLineIsBlank = true;
      boolean sentHeader = false;
      
      while (client.connected()) {
        if (client.available()) {
          char c = client.read();
          if (receiving && c == ' ') receiving = false;//Done receiving
          if (c == '?') receiving = true;
          //found arguments

          if (receiving)  //looking at GET requests
          {
            //LED command is specified with an L
            if (c == 'V') {
              Serial.print("Velocity =");
              pin = client.parseInt();
              Serial.println(pin);
            }
            //speaker command is specified with an S
            else if (c == 'D') {
              Serial.print("Kd = ");
              freq = client.parseInt();
              Serial.println(freq);
            }
          }

          HTTP_req += c;
          if (c == '\n' && currentLineIsBlank) {
            //client.println("HTTP/1.1 200 OK\n\rContent-Type: text/html\n\r\n\r");
            //-------------------------------------------------------------------
            if (HTTP_req.indexOf("readDHT11") > -1) {
              client.println("Velocity&nbsp;&nbsp;&nbsp;&nbsp;: ");
             
            }
            //-------------------------------------------------------------------
        
              delay(2000);
              //client.write("<h2  align=center><font size=7><b>The height of the body </b></font></h2>");
              
              /*myFile = SD.open("dhtajax.htm", O_READ);
              Serial.println(myFile);
              if (1) {
                while (myFile.available()) {
                  client.write(myFile.read());
                  //Serial.write(myFile.read());
                }
                Serial.println("sd girdi");
                myFile.close();
              }
              */
               client.println("HTTP/1.1 200 OK\n\rContent-Type: text/html\n\r\n\r");
      myFile = SD.open("dhtajax.htm", O_READ);
              Serial.println(myFile);
              if (1) {
                while (myFile.available()) {
                  client.write(myFile.read());
                  //Serial.write(myFile.read());
                }
                Serial.println("sd girdi");
                myFile.close();
              }
            
            //-------------------------------------------------------------------
            //HTTP_req = "";
            break;
          }
          //---------------------------------------------------------------------
          if (c == '\n') currentLineIsBlank = true;
          else if (c != '\r') currentLineIsBlank = false;
        }
      }
      delay(10);
      client.stop();
    }
  }
}

void open_me(){
	myFile = SD.open("deneme.txt");
	if (myFile){
		while (myFile.available()) {
			Serial.write(myFile.read());
		}
		myFile.close();
		
	}
}
void loop()
{}

  //===================================================================



This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.