use gzipped file for web ui

This commit is contained in:
andreas 2021-10-17 20:49:51 +02:00
parent 117193fbed
commit 920177fada
4 changed files with 25 additions and 7 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
web/*gz

14
extra_script.py Normal file
View File

@ -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)

View File

@ -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

View File

@ -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://<ip address>/" 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://<ip address>/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();