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">
<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>