diff --git a/.gitignore b/.gitignore index 89cc49c..7977336 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch +web/*gz \ No newline at end of file diff --git a/extra_script.py b/extra_script.py new file mode 100644 index 0000000..6d76e79 --- /dev/null +++ b/extra_script.py @@ -0,0 +1,14 @@ +print("running extra...") +import gzip +import shutil +FILES=['web/index.html'] + +def compressFile(inFile): + outfile=inFile+".gz" + with open(inFile, 'rb') as f_in: + with gzip.open(outfile, 'wb') as f_out: + shutil.copyfileobj(f_in, f_out) + +for f in FILES: + print("compressing %s"%f) + compressFile(f) \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index a9fa875..3e5f840 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,8 +16,9 @@ lib_deps = ttlappalainen/NMEA2000_esp32 @ ^1.0.3 ttlappalainen/NMEA0183 @ ^1.7.1 bblanchon/ArduinoJson@^6.18.5 -board_build.embed_txtfiles= - web/index.html +board_build.embed_files= + web/index.html.gz +extra_scripts= extra_script.py [env:m5stack-atom] board = m5stack-atom diff --git a/src/main.cpp b/src/main.cpp index aedc035..562c985 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#define VERSION "0.0.2" +#define VERSION "0.0.3" //board specific pins #ifdef BOARD_M5ATOM @@ -144,11 +144,14 @@ void debug_log(char* str) { #define JSON_OK "{\"status\":\"OK\"}" //embedded files -extern const char indexFile[] asm("_binary_web_index_html_start"); +extern const uint8_t indexFile[] asm("_binary_web_index_html_gz_start"); +extern const uint8_t indexFileEnd[] asm("_binary_web_index_html_gz_end"); +extern const uint8_t indexFileLen[] asm("_binary_web_index_html_gz_size"); void web_index() // Wenn "http:///" aufgerufen wurde { - webserver.send(200, "text/html", indexFile); //dann Index Webseite senden + webserver.sendHeader(F("Content-Encoding"), F("gzip")); + webserver.send_P(200, "text/html", (const char *)indexFile,(int)indexFileLen); //dann Index Webseite senden } void js_reset() // Wenn "http:///gauge.min.js" aufgerufen wurde @@ -462,11 +465,10 @@ void handle_json() { } - +long lastLog=millis(); void loop() { unsigned int size; int wifi_retry; - webserver.handleClient(); gwWifi.loop(); handle_json();