Guten Morgen Rainer_R,
jetzt verstehe ich! Das liegt sicherlich damit zusammen, dass ich den Sketch schon vor längerer Zeit angepasst habe und die Funktion die Seite direkt darzustellen als "gegeben" hingenommen habe.
Folgender Code öffnet die Datei und gibt im Falle einer HTML-Seite auch den entsprechenden Header mit:
while (client.connected())
{
if (client.available())
{
char c = client.read();
// If it isn't a new line, add the character to the buffer
if (c != '\n' && c != '\r')
{
clientline[index] = c;
index++;
// are we too big for the buffer? start tossing out data
if (index >= BUFSIZ)
index = BUFSIZ -1;
// continue to read more data!
continue;
}
// got a \n or \r new line, which means the string is done
clientline[index] = 0;
// 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("<html><body bgcolor='#444444' text='#c0c0c0'>");
client.println();
// print all the files, use a helper to keep it clean
client.println("<h2>Files:</h2>");
ListFiles(client, LS_SIZE);
client.println("<p><a href='INDEX.HTM'>zurück</a></p></body></html>");
}
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] == '?')
{
//Command to control Arduino Pins
ProcessWebInput(client, filename);
break;
}
else
{
// Print 404
client.println("HTTP/1.1 404 Not Found");
client.println("Content-Type: text/html");
client.println();
client.println("<h2>File Not Found!</h2>");
}
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("<h2>File Not Found!</h2>");
}
break;
}
}
(
Die Anpassung stammt aus meinen Anfängen beim Arduino. Es gibt sicherlich schönere Lösungen mit den Strings.)
Damit kann man die Seiten darstellen, Bilder öffnen oder auch Textdateien im Browser anzeigen.
Der Trick ist halt der Content-Type: text/html.
Bzgl. Hybrid:
Die Dateien, die ich selten bis nie anfasse liegen bei mir auf einem uralten gratis Webserver. Icons und Bilder, JavaScript-Dateien und eine Seite, in deren iFrame die HTML-Seite von der SD-Karte eingebettet wird.
Alleine die Auslagerung des Seiten-Icons hat die Performance beim Laden verdoppelt
