How to read multiple data from SD card

Hello, i'm having problem how to read multiple data from SD card. Right now i do know to read only one data from SD card which is index.html . The problem is, in my index.html got picture but the picture doesn't appear when the index.html load up. Anyone know how to read the picture from SD card while index.html also read.

here is my code

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 66 }; // ip in lan
EthernetServer server(80); //server port

String readString; 

//////////////////////

void setup(){

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT); //pin selected to control
  pinMode(7, OUTPUT); //pin selected to control
  //start Ethernet
  

  //enable serial data print 
  Serial.begin(9600); 
  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");
  
  //Serial.println("server multi pin button test 1.0"); // so I can keep track of what is loaded
  
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  boolean currentLineIsBlank = true;
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 
          //Serial.print(c);
          
        } 

        //if HTTP request has ended
        if (c == '\n' && currentLineIsBlank) {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 
          
       
          client.println("HTTP/1.1 200 OK"); //send new page
            client.println("Content-Type: text/html");
            client.println("Connection:keep-alive");
            client.println(); 
  
         File myFile = SD.open("index.htm"); 
          if (myFile) {

              byte clientBuf[64];
              int clientCount = 0;

            while(myFile.available())
            {
              clientBuf[clientCount] = myFile.read();
              clientCount++; 

              if(clientCount > 63)
              {
                // Serial.println("Packet");
                client.write(clientBuf,64);
                clientCount = 0;
              }
            }
            //final <64 byte cleanup packet
            if(clientCount > 0) client.write(clientBuf,clientCount);            
            // close the file:
            myFile.close();
          }
 
          delay(1);
          button(client);
          //stopping client
          client.stop();
        }
      }
    }
  }
}


void button(EthernetClient client)
{
  
          ///////////////////// control arduino pin
          if(readString.indexOf('2') >0)//checks for 2
          {
            
            digitalWrite(2, HIGH);    // set pin 5 high
            Serial.println("Led 2 On");
            
          }
          if(readString.indexOf('3') >0)//checks for 3
          {
            
            digitalWrite(3, HIGH);    // set pin 5 low
            Serial.println("Led 3 On");
          }
          if(readString.indexOf('5') >0)//checks for 4
          {
           
            digitalWrite(5, HIGH);    // set pin 6 high
            Serial.println("Led 5 On");
          }
          if(readString.indexOf('6') >0)//checks for 5
          {
             
            digitalWrite(6, HIGH);    // set pin 6 low
            Serial.println("Led 6 On");
          }
          if(readString.indexOf('7') >0)//checks for 6
          {
            
            digitalWrite(7, HIGH);    // set pin 7 high
            Serial.println("Led 7 On");
          }
           if(readString.indexOf('4') >0)//checks for 7
          {
            
            digitalWrite(2, LOW);    // set pin 7 low
            digitalWrite(3, LOW);
            digitalWrite(5, LOW);
            digitalWrite(6, LOW);
            Serial.println("All Led OFF");
          }         
 
          //clearing string for next read
          readString="";

        }

this is my html code:

<!DOCTYPE html>

<HTML>
          <HEAD>
          <TITLE>LED NOTIFY STATUS</TITLE>
          </HEAD>
          <BODY>
          <body  style="background-color:rgb(255,153,153);">

          <img src="pic1.jpg" width="200" height="200" align=left alt="pic1">
          <img src="pic2.jpg" width="200" height="200" align=right alt="pic2">   
  
          &nbsp;<font color=black><H1 align=center>LECTURER STATUS</font> </H1>


	  <font color=yellow><H3 align=center>*******PLEASE DOUBLE CLICK ON THE BUTTON ********</font></H3>
          <font color=black><H2 align=center>DAY</font> </H2>
      

          
          <input type=button value=ON style="position:absolute; top:260px; left:450px" onmousedown=location.href='/?on2;'> 
          <input type=button value=OFF style="position:absolute; top:260px; left:550px"  onmousedown=location.href='/?off3;'>
          <input type=button value=Clear style="position:absolute; top:260px; left:650px"  onmousedown=location.href='/?clear5;'>
          <input type=button value=Buzy style="position:absolute; top:260px; left:750px" onmousedown=location.href='/?buzy6;'>    

</BODY>
          </HTML>

You web server code only ever reads

         File myFile = SD.open("index.htm");

You need to parse the request string from the browser and open and return the appropriate file, ie instead of always returning index.html

See
http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html

e.g. an example of the request is

GET /index.html HTTP/1.0

You should also serve the correct mime type for the image and not use

client.println("Content-Type: text/html");

for all data types.

rogerClark, do you have any example code for me to follow?

Yes and no.

I wrote some code to do it with a TLN13AU06 Wifi serial module, but not using an SD card

But you're welcome to look at the code on github, https://github.com/rogerclarkmelbourne/Arduino/blob/master/TLN13UA06_web_server/TLN13UA06_web_server.ino

However I suspect it won't be much use to you as you are not using the same network hardware

thanks for the link given but did you know at where i can edit and add some code that help me to read html file and jpeg based on my coding given?.

because i really don't want to change the code. can i used readString to GET /.html?

I'm sure what you want to do has been done before.

You need to find some better example code, and also your request needs to be in the Networking section. I'll ask the moderators to move it

The problem is, in my index.html got picture but the picture doesn't appear when the index.html load up. Anyone know how to read the picture from SD card while index.html also read.

That's NOT what you need to do. You need to pay attention to what the client is asking for. The response should address what the client asked for, not what you feel like sending.

because i really don't want to change the code.

Tough shit. Get over it.

can i used readString to GET /.html?

readString contains what the client asked for. You need to parse it, so you supply the correct response.

thanks rogerClark, i hope others can help me in this project. i wait for others to give some solution for me.

thank you again rogerClark for your attention :slight_smile:

PaulS,can you give me some example code for me to follow and learn?

PaulS,can you give me some example code for me to follow and learn?

No. You seem to be expecting completed code. You need to take it one step at a time. First step - learn what the client is asking for. That is in readString. All you need to do is print it.