if (strcmp(path, "/SdBrowse") == 0) // Respond with the path that was accessed.
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<body>");
client.println("<head><title>SDBrowse</title></head>");
// print all the files, use a helper to keep it clean
client.println("<h2>Collected Observations<br><br>");
String str;
if (!SPIFFS.begin(true))
{
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}
File root = SPIFFS.open("/");
File file = root.openNextFile();
while (file)
{
if(strncmp(file.name(), "/LOG", 4) == 0)
{
str += "<a href=\"";
str += file.name();
str += "\">";
str += file.name();
str += "</a>";
str += " ";
str += file.size();
str += "<br>\r\n";
}
file = root.openNextFile();
}
client.print(str);
client.println("<br><br>");
client.println("<a href=http://" + publicIP + ":" + LISTEN_PORT + "/Weather >Home</a><br>");
client.println("</body></h2>");
client.println("</html>");
end();
}
Original code by martinayotte, modified for ESP32.
Result in WiFi client/server:
Is there a way to combine HTML and code for Asyncwebserver? PHP code used with HTML?
William