From e8329f258710ff14f75ceb9867ccf7cfe320a3c4 Mon Sep 17 00:00:00 2001 From: Simon Schmidt Date: Sat, 26 Jun 2021 09:02:55 +0200 Subject: [PATCH] moved files, this in on callback for httpserver class --- data/compress.html.gz | Bin 0 -> 591 bytes lib/httpserver/filesys.cpp | 9 +++++++-- lib/httpserver/filesys.h | 4 +++- lib/httpserver/httpserver.cpp | 2 +- lib/httpserver/httpserver.h | 14 ++++++++++++++ test/test_pwm.cpp | 3 +-- 6 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 data/compress.html.gz diff --git a/data/compress.html.gz b/data/compress.html.gz new file mode 100644 index 0000000000000000000000000000000000000000..0ae04ee81c8f09333feddaadc7ee494d45479df7 GIT binary patch literal 591 zcmV-V0hE zoFt}>6WLDJ?$_hk?wYUBLJ?OvwvXTU_&jZ#;Og${$H(sv_b68dTfKb~xMvdqNpyrz zpr~T7y8rg@Zhmuv9tBhta7N=?1-@M~X;+?y3PL%OYR>@496%w@vx|)K4axqbX<@Oe6uF$GsqCnrn}h`4|R;sB$m>tn6a@vXern!ze#A0 z=DQQ=Fe;P1)l29W#f(U8vni|e87Kp6Phhuugwc$@M=@{(;?|a-H%6;&BO&-oR2?Kf0n^eOpvp<=1_q2ozz|JBY@&7bR2=dfbu+ngO*K<36Uk@-;+U>i zDX(hfnjr|!^x0gpfQ;#6W0k*Df)OXhA@_5$8KZ*o5Kr}!>>3t2+7edlr0Xd@S|L<& z;}&94lr>kgiA_6-+lfwnk!X*~S~ca`5}b;y@MVyeqEqkcdK&n4U#m?PLMJ*K28w{9 zyP9u+a0q)YLx4kwuYp{&K`tD~LHkB9UVyTBk$NAv_oD-`dFl5s zDq3`Zmt*u!u{)ET@wy0C57yGbYJ|rK_4$m^S+?mc9Ua@1Q6ytP^p$0AK^@9i&`KdG dVtuWeY9~MSr5X5k!R4E8gI~1gPu(*J001vu9#;SW literal 0 HcmV?d00001 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);