Compare commits
No commits in common. "4e6445fea879e014436828de41b4a38bbd0411fc" and "e8329f258710ff14f75ceb9867ccf7cfe320a3c4" have entirely different histories.
4e6445fea8
...
e8329f2587
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,7 +1,6 @@
|
|||||||
.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
|
@ -1,38 +0,0 @@
|
|||||||
#!/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,15 +1,38 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os, gzip
|
import os, gzip
|
||||||
# https://stackoverflow.com/questions/8156707/gzip-a-file-in-python
|
# https://www.mischianti.org/2020/10/26/web-server-with-esp8266-and-esp32-byte-array-gzipped-pages-and-spiffs-2/
|
||||||
|
|
||||||
src_dir='data'
|
def convert_to_gzip(src, out, f):
|
||||||
out_dir='data_gz'
|
input_file = f'{src}{f}'
|
||||||
|
output_file = f'{out}{f}.gz.h'
|
||||||
|
output_charp = f'{f.replace(".", "_")}_gz'
|
||||||
|
|
||||||
if not 'data_gz' in os.listdir():
|
top = ''
|
||||||
os.mkdir('data_gz')
|
with open(input_file, 'rb') as f_in:
|
||||||
|
gz = gzip.compress(f_in.read())
|
||||||
|
gzlen = len(gz)
|
||||||
|
|
||||||
for f in os.listdir(src_dir):
|
top += f'// filename: {f}.gz.h\n'
|
||||||
with open(f'{src_dir}/{f}', 'rb') as f_in:
|
top += f'#define {output_charp}_len {gzlen}\n'
|
||||||
with gzip.open(f'{out_dir}/{f}.gz', 'wb') as f_out:
|
top += f'const char {output_charp}[] = '
|
||||||
f_out.writelines(f_in)
|
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,12 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>Ich bin ein komrpimierter Test</title>
|
|
||||||
I bims der Head
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
I bims der Body
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
BIN
data/compress.html.gz
Normal file
BIN
data/compress.html.gz
Normal file
Binary file not shown.
13
doku.md
13
doku.md
@ -68,15 +68,10 @@ 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
|
|
||||||
|
@ -46,34 +46,6 @@ public:
|
|||||||
streamFile(f, cont);
|
streamFile(f, cont);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
on("/comp.html", [this]() {
|
|
||||||
File f = open("/comp.html.gz");
|
|
||||||
if (!f) {
|
|
||||||
Serial.println("Failed to open file for reading");
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Serial.println("Streaming /comp.html.gz to client");
|
|
||||||
const String cont = "text/html";
|
|
||||||
streamFile(f, cont);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
onNotFound([this]() {
|
|
||||||
String message = "File Not Found\n\n";
|
|
||||||
message += "URI: ";
|
|
||||||
message += uri();
|
|
||||||
message += "\nMethod: ";
|
|
||||||
message += (method() == HTTP_GET) ? "GET" : "POST";
|
|
||||||
message += "\nArguments: ";
|
|
||||||
message += args();
|
|
||||||
message += "\n";
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < args(); i++) {
|
|
||||||
message += " " + argName(i) + ": " + arg(i) + "\n";
|
|
||||||
}
|
|
||||||
send(404, "text/plain", message);
|
|
||||||
});
|
|
||||||
|
|
||||||
if( this->addRootFileHandler() ){
|
if( this->addRootFileHandler() ){
|
||||||
this->begin();
|
this->begin();
|
||||||
|
20
src/main.cpp
20
src/main.cpp
@ -34,7 +34,8 @@ void timerCallback(void *pArg)
|
|||||||
stairs.task();
|
stairs.task();
|
||||||
}
|
}
|
||||||
|
|
||||||
// port 80, root directory of server '/'
|
// HTTP
|
||||||
|
void handleNotFound();
|
||||||
HTTPServer httpServer(80, "/");
|
HTTPServer httpServer(80, "/");
|
||||||
|
|
||||||
uint32_t _t=0;
|
uint32_t _t=0;
|
||||||
@ -43,6 +44,22 @@ uint32_t _t=0;
|
|||||||
// ===============================================
|
// ===============================================
|
||||||
|
|
||||||
|
|
||||||
|
void handleNotFound() {
|
||||||
|
String message = "File Not Found\n\n";
|
||||||
|
message += "URI: ";
|
||||||
|
message += httpServer.uri();
|
||||||
|
message += "\nMethod: ";
|
||||||
|
message += (httpServer.method() == HTTP_GET) ? "GET" : "POST";
|
||||||
|
message += "\nArguments: ";
|
||||||
|
message += httpServer.args();
|
||||||
|
message += "\n";
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < httpServer.args(); i++) {
|
||||||
|
message += " " + httpServer.argName(i) + ": " + httpServer.arg(i) + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
httpServer.send(404, "text/plain", message);
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
#ifdef WITH_DEBUGGING_ON
|
#ifdef WITH_DEBUGGING_ON
|
||||||
@ -78,6 +95,7 @@ void setup() {
|
|||||||
ota_setup();
|
ota_setup();
|
||||||
|
|
||||||
httpServer.start();
|
httpServer.start();
|
||||||
|
httpServer.onNotFound(handleNotFound);
|
||||||
Serial.println("HTTP server started !");
|
Serial.println("HTTP server started !");
|
||||||
|
|
||||||
stairs.setup();
|
stairs.setup();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user