Trib:
Hallo Thombo84,
du musst eine Unterscheidung machen was für eine Anfrage an den Webserver gestellt wird und dann die Datei anstelle der Webseite zurückliefern.
Wenn ein GET ankommt ohne dass ein weiterer Befehl angehängt ist, so gebe ich die Dateiliste aus.
Klicke ich eine Datei an, so bekomme ich eine neuen Anfrage mit dem Dateinamen. Diesen kann ich abprüfen und sofern diese Datei existiert zurückgeben.
Dann habe ich noch einen Fall mehr eingebaut, der ist natürlich nicht unbedingt nötig. Und zwar kann ich auch eine Steuerung vornehmen in dem ich Befehle mitsende. Die werden mit einem GET? angekündigt.
// Look for substring such as a request to get the root file
if (strstr(clientline, "GET / ") != 0)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("");
client.println();
// print all the files, use a helper to keep it clean
client.println("
Files:
");
ListFiles(client, LS_SIZE);
client.println("
zurück
");
}
else if (strstr(clientline, "GET /") != 0)
{
// this time no space after the /, so a sub-file!
char *filename;
filename = clientline + 5; // look after the "GET /" (5 chars)
// a little trick, look for the " HTTP/1.1" string and
// turn the first character of the substring into a 0 to clear it out.
(strstr(clientline, " HTTP"))[0] = 0;
// print the file we want
// Serial.println(filename);
// File couldn´t be opened
if (! file.open(&root, filename, O_READ))
{
//If it is an command, work with it
if(filename[0] == '?')
{
//Function to control Pins, ect.
ProcessInput(client, filename);
break;
}
else
{
// Print 404
client.println("HTTP/1.1 404 Not Found");
client.println("Content-Type: text/html");
client.println();
client.println("
File Not Found!
");
}
break;
}
//It really is a File
// PgmPrint("Opened!");
client.println("HTTP/1.1 200 OK");
if(strstr(clientline, "HTM") != 0 || strstr(clientline, "TML") != 0)
client.println("Content-Type: text/html");
else
client.println("Content-Type: text/plain");
client.println();
int16_t c;
while ((c = file.read()) > 0)
{
// uncomment the serial to debug (slow!)
//Serial.print((char)c);
client.print((char)c);
}
file.close();
}
else
{
// everything else is a 404
client.println("HTTP/1.1 404 Not Found");
client.println("Content-Type: text/html");
client.println();
client.println("
File Not Found!
");
}
Was ich darüber hinaus noch gemacht habe ist, dass ich unterscheide ob die Datei eine richtige Datei ist oder eine HTML-Seite. Dann kann man im Header den Content-Type setzen und die Seite wird direkt ausgegeben. Ansonsten sieht man nur den Quelltext. Funktioniert mit Bildern hervorragend!
Gruß,
trib
Danke für den Hinweis 
Kleine Frage am Rande: Als was hast du "file" deklariert?
Ich versuche das gerade an meinen Sketch anzubinden, bekomme bei file.open(&root, entry.name(), O_READ))
aber "file was not declared in this scope"