ESP8266 Treppenlichtsteuerung mit OTA zum Firmware Upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

extra_script.py 949B

12345678910111213141516171819202122232425262728293031323334
  1. import os, gzip
  2. # https://www.mischianti.org/2020/10/26/web-server-with-esp8266-and-esp32-byte-array-gzipped-pages-and-spiffs-2/
  3. def convert_to_gzip(src, out, f):
  4. input_file = f'{src}{f}'
  5. output_file = f'{out}{f}.gz.h'
  6. output_charp = f'{f.replace(".", "_")}_gz'
  7. top = ''
  8. with open(input_file, 'rb') as f_in:
  9. gz = gzip.compress(f_in.read())
  10. gzlen = len(gz)
  11. top += f'// filename: {f}.gz.h\n'
  12. top += f'#define {output_charp}_len {gzlen}\n'
  13. top += f'const char {output_charp}[] = '
  14. top += '{'
  15. with open(output_file, 'wb') as f_out:
  16. for i, b in enumerate(gz):
  17. if not i%10:
  18. top += '\n '
  19. top += f'0x{b:02X}, '
  20. top = top[:-2]
  21. top += '};'
  22. f_out.write(top.encode(encoding='utf-8'))
  23. src='include/http/'
  24. out='include/'
  25. for f in os.listdir(src):
  26. convert_to_gzip(src, out, f)