Bonjour j'ai un problème j'aimerai que mon site web s'affiche correctement j'ai donc fait une boucle pour faire appel a toutes les images .htm. Mais le problème est que ma boucle prends en compte uniquement la page index.htm, le style.css et l'image de fond (fond.png). Est ce que vous savez pourquoi mes autres images et page ne s'affiche pas merci.
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
// MAC address from Ethernet shield sticker under board
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x1F, 0xED };
IPAddress ip(169, 254, 73, 50); // IP address, may need to change depending on network
EthernetServer server(80); // create a server at port 80
File webFile;
String HTTP_req = ""; // stores the received HTTP request
void setup()
{
Ethernet.begin(mac, ip); // initialize Ethernet device
server.begin(); // start to listen for clients
Serial.begin(9600); // for debugging
// initialize SD card
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
return; // init failed
}
Serial.println("SUCCESS - SD card initialized.");
// check for index.htm file
if (!SD.exists("index.htm")) {
Serial.println("ERROR - Can't find index.htm file!");
return; // can't find index file
}
Serial.println("SUCCESS - Found index.htm file.");
}
void loop()
{
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
HTTP_req += c; // save HTTP request character
// print HTTP request character to serial monitor
Serial.print(c);
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send web page
if ((HTTP_req.indexOf("GET / ") > -1) ||
(HTTP_req.indexOf("GET /index.htm") > -1)) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
webFile = SD.open("index.htm"); // open web page file
}
else if (HTTP_req.indexOf("GET /style.css") > -1) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
webFile = SD.open("style.css"); // open web page file
}
else if (HTTP_req.indexOf("GET /en_index.htm") > -1) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
webFile = SD.open("en_index.htm"); // open web page file
}
else if (HTTP_req.indexOf("GET /en_style.css") > -1) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
webFile = SD.open("en_style.css"); // open web page file
}
else if (HTTP_req.indexOf("GET /fond.png") > -1) {
webFile = SD.open("fond.png");
if (webFile) {
client.println("HTTP/1.1 200 OK");
client.println();
}
}
else if (HTTP_req.indexOf("GET /logo.png") > -1) {
webFile = SD.open("logo.png");
if (webFile) {
client.println("HTTP/1.1 200 OK");
client.println();
}
}
else if (HTTP_req.indexOf("GET /en.png") > -1) {
webFile = SD.open("en.png");
if (webFile) {
client.println("HTTP/1.1 200 OK");
client.println();
}
}
else if (HTTP_req.indexOf("GET /fr.png") > -1) {
webFile = SD.open("fr.png");
if (webFile) {
client.println("HTTP/1.1 200 OK");
client.println();
}
}
if (webFile) {
while(webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}
HTTP_req = ""; // empty the string
break;
}
// 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)
}