Solved: appears to be a memory allocation issue. I had 29k of free heap space, that does not appear to be enough for the streamFile implementation. I changed the code to manually send the file in chunks, and it’s working now.
I am using the EPS Arduino package 3.1.2 (which I think is the latest released one), and using the ESP8266WebServer library to serve up a simple web page.
Part of the web page is using a JS library, which is stored on the SPIFFS. The library is 47k in size.
The issue is, that I can’t get the web server to send the file to client correctly.
I have tried serving it as static content, with adding:
server.serveStatic( "/htmx.min.js", SPIFFS, "/htmx.min.js" );
When using this method, I see the following in the serial monitor:
Request: /htmx.min.js
Arguments:
final list of key/value pairs:
[String] ‘Content-Ty … ep-alive
‘: Reallocating large String(151 -> 177 bytes)
and then nothing else.
So I tried with streamFile instead.
server.on( "/htmx.min.js", []() {
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
SPIFFS.begin();
if ( SPIFFS.exists( "/htmx.min.js" ) ) {
File f = SPIFFS.open( "/htmx.min.js", "r" );
if ( f ) {
server.streamFile( f, "application/javascript" );
f.close();
} else {
server.send( 500, "text/plain", "" ); // unable to open file
}
} else
server.send( 404, "text/plain", "" ); // file doesn't exist
SPIFFS.end();
});
But again, radio silence. Nothing appear to be send. This time, there’s not really any indication in the console as to why it’s not sending data.
I did a Serial.print statement, just to check that the server.on snippet indeed is called.
Anyone know why ESP8266WebServer is not able to send 47k of JS data from SPIFFS?