modify script for new way of serving gz files
This commit is contained in:
parent
10b57ca516
commit
4e6445fea8
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
|||||||
.pio
|
.pio
|
||||||
.vscode
|
.vscode
|
||||||
compress
|
compress
|
||||||
|
data_gz
|
||||||
platformio.ini
|
platformio.ini
|
||||||
include/wifi_credentials.h
|
include/wifi_credentials.h
|
||||||
include/*.gz.h
|
include/*.gz.h
|
38
create_gz_c_arr.py
Normal file
38
create_gz_c_arr.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os, gzip
|
||||||
|
# https://www.mischianti.org/2020/10/26/web-server-with-esp8266-and-esp32-byte-array-gzipped-pages-and-spiffs-2/
|
||||||
|
|
||||||
|
def convert_to_gzip(src, out, f):
|
||||||
|
input_file = f'{src}{f}'
|
||||||
|
output_file = f'{out}{f}.gz.h'
|
||||||
|
output_charp = f'{f.replace(".", "_")}_gz'
|
||||||
|
|
||||||
|
top = ''
|
||||||
|
with open(input_file, 'rb') as f_in:
|
||||||
|
gz = gzip.compress(f_in.read())
|
||||||
|
gzlen = len(gz)
|
||||||
|
|
||||||
|
top += f'// filename: {f}.gz.h\n'
|
||||||
|
top += f'#define {output_charp}_len {gzlen}\n'
|
||||||
|
top += f'const char {output_charp}[] = '
|
||||||
|
top += '{'
|
||||||
|
|
||||||
|
with open(output_file, 'wb') as f_out:
|
||||||
|
for i, b in enumerate(gz):
|
||||||
|
if not i%10:
|
||||||
|
top += '\n '
|
||||||
|
top += f'0x{b:02X}, '
|
||||||
|
top = top[:-2]
|
||||||
|
top += '};'
|
||||||
|
f_out.write(top.encode(encoding='utf-8'))
|
||||||
|
|
||||||
|
|
||||||
|
src='data/'
|
||||||
|
out='compress/'
|
||||||
|
|
||||||
|
if not 'compress' in os.listdir():
|
||||||
|
os.mkdir('compress')
|
||||||
|
|
||||||
|
for f in os.listdir(src):
|
||||||
|
convert_to_gzip(src, out, f)
|
@ -1,38 +1,15 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os, gzip
|
import os, gzip
|
||||||
# https://www.mischianti.org/2020/10/26/web-server-with-esp8266-and-esp32-byte-array-gzipped-pages-and-spiffs-2/
|
# https://stackoverflow.com/questions/8156707/gzip-a-file-in-python
|
||||||
|
|
||||||
def convert_to_gzip(src, out, f):
|
src_dir='data'
|
||||||
input_file = f'{src}{f}'
|
out_dir='data_gz'
|
||||||
output_file = f'{out}{f}.gz.h'
|
|
||||||
output_charp = f'{f.replace(".", "_")}_gz'
|
|
||||||
|
|
||||||
top = ''
|
if not 'data_gz' in os.listdir():
|
||||||
with open(input_file, 'rb') as f_in:
|
os.mkdir('data_gz')
|
||||||
gz = gzip.compress(f_in.read())
|
|
||||||
gzlen = len(gz)
|
|
||||||
|
|
||||||
top += f'// filename: {f}.gz.h\n'
|
for f in os.listdir(src_dir):
|
||||||
top += f'#define {output_charp}_len {gzlen}\n'
|
with open(f'{src_dir}/{f}', 'rb') as f_in:
|
||||||
top += f'const char {output_charp}[] = '
|
with gzip.open(f'{out_dir}/{f}.gz', 'wb') as f_out:
|
||||||
top += '{'
|
f_out.writelines(f_in)
|
||||||
|
|
||||||
with open(output_file, 'wb') as f_out:
|
|
||||||
for i, b in enumerate(gz):
|
|
||||||
if not i%10:
|
|
||||||
top += '\n '
|
|
||||||
top += f'0x{b:02X}, '
|
|
||||||
top = top[:-2]
|
|
||||||
top += '};'
|
|
||||||
f_out.write(top.encode(encoding='utf-8'))
|
|
||||||
|
|
||||||
|
|
||||||
src='data/'
|
|
||||||
out='compress/'
|
|
||||||
|
|
||||||
if not 'compress' in os.listdir():
|
|
||||||
os.mkdir('compress')
|
|
||||||
|
|
||||||
for f in os.listdir(src):
|
|
||||||
convert_to_gzip(src, out, f)
|
|
Binary file not shown.
Binary file not shown.
13
doku.md
13
doku.md
@ -68,10 +68,15 @@ TODO:
|
|||||||
- maybe compress files ?
|
- maybe compress files ?
|
||||||
|
|
||||||
|
|
||||||
LED Flickering issue
|
### LED Flickering issue
|
||||||
https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
||||||
|
PlatformIO Library veraltet !!
|
||||||
PlatformIO Library veraltet
|
|
||||||
|
|
||||||
|
|
||||||
###TIMER in OTA unterbrechen !!!!!
|
### TIMER in OTA unterbrechen !!!!!
|
||||||
|
|
||||||
|
### further improvments
|
||||||
|
with streamFile gzip encoded Files can be sent
|
||||||
|
this reduces space on fs !
|
||||||
|
new easier script needed to just convert to .gz
|
||||||
|
maybe measure timings on ESP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user