Skip to content

Commit

Permalink
Added debug output (file serve)
Browse files Browse the repository at this point in the history
  • Loading branch information
visualapproach committed May 8, 2023
1 parent c423535 commit 11bfdcf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
Binary file modified Code/fw/firmware.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion Code/fw/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-05-02-1000
2023-05-08-1052
2 changes: 1 addition & 1 deletion Code/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <WiFi.h>
#endif
#define DEVICE_NAME "layzspa"
#define FW_VERSION "2023-05-02-1000"
#define FW_VERSION "2023-05-08-1052"

#define HA_PREFIX "homeassistant"
#define PROM_NAMESPACE "layzspa"
Expand Down
24 changes: 13 additions & 11 deletions Code/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,13 @@ void handleNotFound()

String getContentType(const String& filename)
{
if (filename.endsWith(".html")) return "text/html";
else if (filename.endsWith(".css")) return "text/css";
else if (filename.endsWith(".js")) return "application/javascript";
else if (filename.endsWith(".ico")) return "image/x-icon";
else if (filename.endsWith(".gz")) return "application/x-gzip";
else if (filename.endsWith(".json")) return "application/json";
return "text/plain";
if (filename.endsWith(".html")) return F("text/html");
else if (filename.endsWith(".css")) return F("text/css");
else if (filename.endsWith(".js")) return F("application/javascript");
else if (filename.endsWith(".ico")) return F("image/x-icon");
else if (filename.endsWith(".gz")) return F("application/x-gzip");
else if (filename.endsWith(".json")) return F("application/json");
return F("text/plain");
}

/**
Expand All @@ -712,12 +712,14 @@ bool handleFileRead(String path)
String pathWithGz = path + ".gz";
if (LittleFS.exists(pathWithGz) || LittleFS.exists(path)) { // If the file exists, either as a compressed archive, or normal
if (LittleFS.exists(pathWithGz)) // If there's a compressed version available
path += ".gz"; // Use the compressed version
path += ".gz"; // Use the compressed version
File file = LittleFS.open(path, "r"); // Open the file
// size_t sent = server.streamFile(file, contentType); // Send it to the client
server.streamFile(file, contentType); // Send it to the client
size_t fsize = file.size();
size_t sent = server.streamFile(file, contentType); // Send it to the client
// server.streamFile(file, contentType); // Send it to the client
file.close(); // Close the file again
// Serial.println("HTTP > file sent: " + path + " (" + sent + " bytes)");
Serial.println(F("File size: ") + String(fsize));
Serial.println(F("HTTP > file sent: ") + path + F(" (") + sent + F(" bytes)"));
return true;
}
// Serial.println("HTTP > file not found: " + path); // If the file doesn't exist, return false
Expand Down

0 comments on commit 11bfdcf

Please sign in to comment.