diff --git a/data/compress.html.gz b/data/compress.html.gz new file mode 100644 index 0000000..0ae04ee Binary files /dev/null and b/data/compress.html.gz differ diff --git a/lib/httpserver/filesys.cpp b/lib/httpserver/filesys.cpp index 0e3f42b..b315964 100644 --- a/lib/httpserver/filesys.cpp +++ b/lib/httpserver/filesys.cpp @@ -4,7 +4,7 @@ // deleteFile("/hello.txt"); // writeFile("/hello.txt", "Hello "); // appendFile("/hello.txt", "World!\n\r"); -// readFile("/hello.txt"); +// printFile("/hello.txt"); // listDir("/"); FSInfo fsinfo; @@ -58,7 +58,12 @@ void ls(const char * dirname) { Serial.println(); } -void readFile(const char * path) { +File open(const char * path) { + return LittleFS.open(path, "r"); +} + + +void printFile(const char * path) { Serial.printf("Reading file: %s\n\r", path); File file = LittleFS.open(path, "r"); diff --git a/lib/httpserver/filesys.h b/lib/httpserver/filesys.h index 8f756ea..708c1f4 100644 --- a/lib/httpserver/filesys.h +++ b/lib/httpserver/filesys.h @@ -5,8 +5,10 @@ bool mount_fs(); bool format_fs(); +File open(const char * path); + void ls(const char * dirname); -void readFile(const char * path); +void printFile(const char * path); void writeFile(const char * path, const char * message); void appendFile(const char * path, const char * message); void renameFile(const char * path1, const char * path2); diff --git a/lib/httpserver/httpserver.cpp b/lib/httpserver/httpserver.cpp index ae75c37..36df250 100644 --- a/lib/httpserver/httpserver.cpp +++ b/lib/httpserver/httpserver.cpp @@ -14,4 +14,4 @@ bool HTTPServer::addRootFileHandler() { this->serveStatic("/favicon.png", LittleFS, "/favicon.png"); return true; -} \ No newline at end of file +} diff --git a/lib/httpserver/httpserver.h b/lib/httpserver/httpserver.h index 38c5370..3a7e848 100644 --- a/lib/httpserver/httpserver.h +++ b/lib/httpserver/httpserver.h @@ -33,6 +33,20 @@ public: this->listRoot(); Serial.printf("\n\r"); + // https://stackoverflow.com/questions/7627098/what-is-a-lambda-expression-in-c11 + on("/compress.html", [this]() { + File f = open("/compress.html.gz"); + if (!f) { + Serial.println("Failed to open file for reading"); + } + else + { + Serial.println("Streaming /compress.html.gz to client"); + const String cont = "text/html"; + streamFile(f, cont); + } + }); + if( this->addRootFileHandler() ){ this->begin(); Serial.printf("[HTTPServer] Server active on Port 80 !\n\r"); diff --git a/test/test_pwm.cpp b/test/test_pwm.cpp index e03383d..1c2ef4f 100644 --- a/test/test_pwm.cpp +++ b/test/test_pwm.cpp @@ -1,6 +1,5 @@ -#include +// #include #include "treppe.h" - #include Treppe stairs(10);