ArduinoMongoose
ArduinoMongoose copied to clipboard
Generic support for embedding/serving static content
Move the code from https://github.com/OpenEVSE/ESP32_WiFi_V3.x/ for embeding/serving static content embedded into the firmware.
Maybe also consider alternative methods, eg https://github.com/Aircoookie/WLED
Mongoose, at least at v7.7, does have some support for this - see mg_http_serve_file()
. It seems the paths they use rely on some basic filesystem-ish methods, which we may need to have for TLS support anyway.
which we may need to have for TLS support anyway.
Looks like we don't need that filesystem support for TLS, mongoose has got this clever shortcut for files that start with -
, which the certs do: https://github.com/cesanta/mongoose/blob/76e6b23a4f0261dd534d33632f42ea1bba99dc85/mongoose.c#L5127-L5132
I don't think if their filesystem support is really appropriate for serving general static assets - it reads the whole file at once, in to a buffer allocated with calloc()
. So, that mg_http_serve_file()
method probably isn't useful for this.
That is rubbish, I think the code in the OpenEVSE works reasonably well. Doing a bit of work on the script to make it a bit more flexible (for the v2 UI). It would also be nice to support any Arduino filesystem as well, but this needs the ability to override the normal file system calls and replace with the Arduino equipment.
You could start with the most common file system used by ESP Arduino, which is LittleFS. It would be really awesome if we could throw a file system pointer to the static file serving method of mongoose or to the routes like in the case of Me no Dev's ESP async webserver.
fs::LittleFSFS sysFS;
server.serveStatic("/",sysFS,"/").setCacheControl(ONE_HOUR_CACHE_TIME);
server.on("/",HTTP_GET,[this](AsyncWebServerRequest *request){
AsyncWebServerResponse *response = request->beginResponse(
sysFS,
INDEX_PATH,
"text/html"
);
response->addHeader("Content-Encoding", "gzip");
request->send(response);
});
serveStatic method looks like this in this library
AsyncStaticWebHandler& AsyncWebServer::serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_control){
AsyncStaticWebHandler* handler = new AsyncStaticWebHandler(uri, fs, path, cache_control);
addHandler(handler);
return *handler;
}
anyone could serve static files with LittleFS?
When you want to do OTA updates, it is convenient to merge the web UI files on to the firmware so you don't need a secondary process for updating them.
What I want is to serve a htnl files in littlefs
That is what the goal of #16 is