Closed DaeMonSxy closed 2 months ago
Wondering if this is not linked to #70... Really weird!
Well can be... However I am not loading pages one after another in fast pace.
After esp8266 bootup, nothing happens ( no crash) then if i type in the webpage, immediatelly crashing - no reloads or fast clicks, not intentionall communication (ws)
Hence I did not link that to "fast page change" - thats heap issue i believe
@DaeMonSxy : if you can adapt one of the example in the project, or send me an .ino file I can put in the project (in examples) as a reproductible use case, I can try to have a look with my D1 Mini.
can you tell us what is behind the macro FPSTRP
.
Have you tried it without the macro?
AsyncWebServerResponse *response = request->beginResponse(200, F("text/html; charset=UTF-8"), zippedHtml, len);
response->addHeader(F("content-type"), "text/html; charset=UTF-8");
response->addHeader(F("Content-Encoding"), "gzip");
request->send(response);
I too use ESP8266 with latest library version, serving g-zipped contents without any problem.
Thanks @lumapu ! I didn't even notice FPSTRP
! ;-)
yes, i have tried "simplified" versioned also.
// Using F() macro to store strings in flash memory
const char TEXT_HTML[] PROGMEM = "text/html";
const char TEXT_CSS[] PROGMEM = "text/css";
const char APPLICATION_JS[] PROGMEM = "application/javascript";
const char CONTENT_ENCODING[] PROGMEM = "Content-Encoding";
const char GZIP[] PROGMEM = "gzip";
#define PSTRP(s) (reinterpret_cast<const __FlashStringHelper *>(s))
#define FPSTRP(s) (reinterpret_cast<const char *>(s))
also tried without F macros, same issue happened.(thats been my first thought also.)
@DaeMonSxy : if you can adapt one of the example in the project, or send me an .ino file I can put in the project (in examples) as a reproductible use case, I can try to have a look with my D1 Mini.
well, im not sure i can do that soon, going to be busy this days.
I do not use ino or arduino in past few years - im on platformio. having a quite big code, but will check closer to weekend if i can streamline the code just to have this block of code extracted for checking.
meanwhile, did a bit of checking, if i pass html code: - it is working OK
const char SAMPLE_HTML[] PROGMEM = "<html><body><h1>Sample Page</h1></body></html>";
the crash occurs if used: uint - crashing
**const uint8_t system_html[] PROGMEM = {
0x1f,0x8b,....
};**
meanwhile, did a bit of checking, if i pass html code: - it is working OK
Yeah but it prevents you from gzip encoding, so not ideal...
Did you try same code as @lumapu, without using your macros ?
yes, same - crashing : same without progmem variables below.
` const char CONTENT_ENCODING[] PROGMEM = "Content-Encoding"; const char GZIP[] PROGMEM = "gzip";
const uint8_t system_html[] PROGMEM = { 0x1f,0x8b,....... };
//----------------------------------------------------------------------------
void sendHTMLResponse(AsyncWebServerRequest request, const uint8_t htmlContent, size_t htmlSize, const char *contentType, html_pages_t setpage) { auto response = request->beginResponse(200, contentType, htmlContent, htmlSize); response->addHeader(CONTENT_ENCODING, GZIP); request->send(response); current_html_page = setpage; }
WServer.on("/syst", HTTP_GET, [](AsyncWebServerRequest *request) { sendHTMLResponse(request, system_html, sizeof(system_html), (TEXT_HTML), P_SYSTEM); });
//----------------------------------------------------------------------------
Exception (3): epc1=0x4000bf64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x40269d2f depc=0x00000000
LoadStoreError: Processor internal physical address or data error during load or store excvaddr=0x40269d2f in system_get_sdk_version at ??:?
stack>>>
<<<stack<<<
0x40269d2f in system_get_sdk_version at ??:?
0x4021fa41 in AsyncAbstractResponse::AsyncAbstractResponse(std::function<String (String const&)>) at /Users/daemons/platformio_libdeps/ESP8266/ESPAsyncWebServer/src/WebResponses.cpp:405
0x40279136 in system_get_sdk_version at ??:?
0x40269d2f in system_get_sdk_version at ??:?
0x4021facd in AsyncProgmemResponse::AsyncProgmemResponse(int, char const, unsigned char const, unsigned int, std::function<String (String const&)>) at /Users/daemons/platformio_libdeps/ESP8266/ESPAsyncWebServer/src/WebResponses.cpp:826
0x40269d2f in system_get_sdk_version at ??:?
0x40100c34 in malloc at /Users/daemons/platformio_packages/framework-arduinoespressif8266/cores/esp8266/umm_malloc/umm_malloc.cpp:912
0x40279136 in system_get_sdk_version at ??:?
0x40269d2f in system_get_sdk_version at ??:?
0x4021cd24 in AsyncWebServerRequest::beginResponse(int, char const, unsigned char const, unsigned int, std::function<String (String const&)>) at /Users/daemons/platformio_libdeps/ESP8266/ESPAsyncWebServer/src/WebRequest.cpp:699
0x40229cc8 in String::equals(String const&) const at /Users/daemons/platformio_packages/framework-arduinoespressif8266/cores/esp8266/WString.cpp:543
(inlined by) String::equals(String const&) const at /Users/daemons/platformio_packages/framework-arduinoespressif8266/cores/esp8266/WString.cpp:542
0x40229589 in String::copy(char const, unsigned int) at /Users/daemons/platformio_packages/framework-arduinoespressif8266/cores/esp8266/WString.cpp:274
0x4020920c in sendHTMLResponse(AsyncWebServerRequest, unsigned char const, unsigned int, char const, html_pages_t) at ./web_handlers/WServer.h:61
0x4021bf9e in find_if<__gnu_cxx::normal_iterator<String, std::vector
--------------- CUT HERE FOR EXCEPTION DECODER ---------------`
I think found the problem.
We're using the following prototype:
AsyncWebServerResponse* AsyncWebServerRequest::beginResponse(int code, const char* contentType, const uint8_t* content, size_t len, AwsTemplateProcessor callback);
You're passing a const char*
from PROGMEM
type casted to const char *
as the second argument to beginResponse
. For me it feels that beginResponse
can't consume a PROGMEM-const-char-ptr.
I tried that by implementing your macros step by step to my code. Once I started passing contentType
from PROGREM the issue occured.
Then digging further I found out that the last argument of your function
void sendStaticResponse(AsyncWebServerRequest *request, const uint8_t *htmlContent, size_t htmlSize, const char *contentType);
has to be
void sendStaticResponse(AsyncWebServerRequest *request, const uint8_t *htmlContent, size_t htmlSize, const _FlashStringHelper* contentType);
now you have to pass the text/css
with your other macro PSTRP(TEXT_CSS)
. With that change the code also works as expected.
In the end I don't know if this webserver library can be improved or your code has to be changed. I'm curious how this will be solved đ
side note: my code size shrinked a few bytes using the macros, thanks for sharing đ
before changing, passing content type using F(...)
RAM: [==== ] 40.4% (used 33104 bytes from 81920 bytes)
Flash: [==== ] 39.8% (used 415773 bytes from 1044464 bytes)
after change using macros FPSTRP and PSTRP
RAM: [==== ] 40.4% (used 33072 bytes from 81920 bytes)
Flash: [==== ] 39.8% (used 415357 bytes from 1044464 bytes)
The other option is to use String
, like it is done at a few other places in this lib for esp8266:
beginResponse(int code, const String& contentType, const uint8_t* content, size_t len
and
auto response = request->beginResponse(200, String(contentType), htmlContent, htmlSize);
or... use const String& contentType in your sendStaticResponse
declaration.
I don't think the library is at fault here because beginResponse_P
variants were reported to work, and those only have a signature with const String& contentType
, so an implicit conversion (done by Arduino String class) was done when calling it. The implicit conversion cannot be done with beginResponse
since beginResponse
is overloaded to support String and char*.
@lumapu : thanks for pointing to the right direction! ESP8266 is definitely ugly ! 4-5 years remaining and it is dead!
beginResponse_P works okay, but it will be deprecated, so i turned to beginResponse ... now crashing..
platform: esp8266
page content:
[[deprecated("Replaced by beginResponse(...)")]] AsyncWebServerResponse beginResponse_P(int code, const String& contentType, const uint8_t content, size_t len, AwsTemplateProcessor callback = nullptr) { return beginResponse(code, contentType, content, len, callback); }
crash: