put the chunked response stuff into own function, fix html javascript include
This commit is contained in:
parent
55997e82eb
commit
f7f5fe073b
2 changed files with 24 additions and 20 deletions
|
@ -34,7 +34,7 @@ const char* Header_HTML PROGMEM = R"(<!DOCTYPE html>
|
|||
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>%GROWNAME% - CanGrow v%CGVER%</title>
|
||||
<link rel='stylesheet' href='/cangrow.css'>
|
||||
<link rel='script' href='/cangrow.js'>
|
||||
<script type='text/javascript' src='/cangrow.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
<ul class='nav'><li><a href='/'>🌱 %GROWNAME%</a></li>
|
||||
|
|
|
@ -398,29 +398,33 @@ String Proc_WebPage_system_output_add_POST(const String& var) {
|
|||
}
|
||||
|
||||
|
||||
auto Chunk_system_output_add_HTML(uint8_t *buffer, size_t maxlen, size_t index) -> size_t {
|
||||
// https://github.com/mathieucarbou/ESPAsyncWebServer?tab=readme-ov-file#chunked-response-containing-templates
|
||||
//Write up to "maxLen" bytes into "buffer" and return the amount written.
|
||||
//index equals the amount of bytes that have been already sent
|
||||
//You will be asked for more data until 0 is returned
|
||||
//Keep in mind that you can not delay or yield waiting for more data!
|
||||
|
||||
// https://forum.arduino.cc/t/espasyncwebserver-replay-page-size/1049106/19
|
||||
// https://forum.arduino.cc/t/strlen-and-progmem/629376/3 - get len of PROGMEM
|
||||
// https://forum.arduino.cc/t/strlen-and-progmem/629376/3
|
||||
size_t len_html = strlen_P(reinterpret_cast<const char *>(Page_system_output_add_HTML));
|
||||
size_t len = min(maxlen, len_html - index);
|
||||
Serial.printf(":: [Webserver:system:output:add(Chunked)] Sending len %u bytes , maxlen %u, index %u, sizeof %u\n", len, maxlen, index, len_html);
|
||||
memcpy(buffer, Page_system_output_add_HTML + index, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
// I accidently tried chunked response but as the output config page might get pretty big
|
||||
// i leave it as chunked response
|
||||
void WebPage_system_output_add(AsyncWebServerRequest *request) {
|
||||
if(request->method() == HTTP_POST) {
|
||||
|
||||
Serial.println(":: [Webserver:system:output:add] [POST] hello");
|
||||
|
||||
AsyncWebServerResponse *response = request->beginChunkedResponse("text/html", Chunk_system_output_add_HTML, Proc_WebPage_system_output_add_POST);
|
||||
request->send(response);
|
||||
} else {
|
||||
// https://github.com/mathieucarbou/ESPAsyncWebServer?tab=readme-ov-file#chunked-response-containing-templates
|
||||
//Write up to "maxLen" bytes into "buffer" and return the amount written.
|
||||
//index equals the amount of bytes that have been already sent
|
||||
//You will be asked for more data until 0 is returned
|
||||
//Keep in mind that you can not delay or yield waiting for more data!
|
||||
|
||||
// https://forum.arduino.cc/t/espasyncwebserver-replay-page-size/1049106/19
|
||||
// https://forum.arduino.cc/t/strlen-and-progmem/629376/3 - get len of PROGMEM
|
||||
AsyncWebServerResponse *response = request->beginChunkedResponse("text/html", [](uint8_t *buffer, size_t maxlen, size_t index) -> size_t {
|
||||
// https://forum.arduino.cc/t/strlen-and-progmem/629376/3
|
||||
size_t len_html = strlen_P(reinterpret_cast<const char *>(Page_system_output_add_HTML));
|
||||
size_t len = min(maxlen, len_html - index);
|
||||
Serial.printf(":: [Webserver:system:output:add(Chunked)] Sending len %u bytes , maxlen %u, index %u, sizeof %u\n", len, maxlen, index, len_html);
|
||||
memcpy(buffer, Page_system_output_add_HTML + index, len);
|
||||
return len;
|
||||
}, Proc_WebPage_system_output_add);
|
||||
AsyncWebServerResponse *response = request->beginChunkedResponse("text/html", Chunk_system_output_add_HTML, Proc_WebPage_system_output_add);
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue