Serve webapp from flash instead of LITTLEFS
This allows a web based firmware update by just replacing one bin file
This commit is contained in:
parent
49f398e797
commit
68c451aa82
@ -20,6 +20,7 @@ platform = espressif32
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-D=${PIOENV}
|
||||
-DCOMPONENT_EMBED_FILES=data/index.html.gz:data/zones.json.gz:data/favicon.ico:data/js/app.js.gz
|
||||
|
||||
lib_deps =
|
||||
https://github.com/me-no-dev/ESPAsyncWebServer.git
|
||||
|
||||
@ -17,6 +17,16 @@ WebApiClass::WebApiClass()
|
||||
{
|
||||
}
|
||||
|
||||
extern const uint8_t file_index_html_start[] asm("_binary_data_index_html_gz_start");
|
||||
extern const uint8_t file_favicon_ico_start[] asm("_binary_data_favicon_ico_start");
|
||||
extern const uint8_t file_zones_json_start[] asm("_binary_data_zones_json_gz_start");
|
||||
extern const uint8_t file_app_js_start[] asm("_binary_data_js_app_js_gz_start");
|
||||
|
||||
extern const uint8_t file_index_html_end[] asm("_binary_data_index_html_gz_end");
|
||||
extern const uint8_t file_favicon_ico_end[] asm("_binary_data_favicon_ico_end");
|
||||
extern const uint8_t file_zones_json_end[] asm("_binary_data_zones_json_gz_end");
|
||||
extern const uint8_t file_app_js_end[] asm("_binary_data_js_app_js_gz_end");
|
||||
|
||||
void WebApiClass::init()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
@ -45,7 +55,36 @@ void WebApiClass::init()
|
||||
_server.on("/api/inverter/edit", HTTP_POST, std::bind(&WebApiClass::onInverterEdit, this, _1));
|
||||
_server.on("/api/inverter/del", HTTP_POST, std::bind(&WebApiClass::onInverterDelete, this, _1));
|
||||
|
||||
_server.serveStatic("/", LittleFS, "/", "max-age=86400").setDefaultFile("index.html");
|
||||
_server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", file_index_html_start, file_index_html_end - file_index_html_start);
|
||||
response->addHeader("Content-Encoding", "gzip");
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
_server.on("/index.html", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", file_index_html_start, file_index_html_end - file_index_html_start);
|
||||
response->addHeader("Content-Encoding", "gzip");
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
_server.on("/favicon.ico", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
AsyncWebServerResponse *response = request->beginResponse_P(200, "image/x-icon", file_favicon_ico_start, file_favicon_ico_end - file_favicon_ico_start);
|
||||
response->addHeader("Content-Encoding", "gzip");
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
_server.on("/zones.json", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
AsyncWebServerResponse *response = request->beginResponse_P(200, "application/json", file_zones_json_start, file_zones_json_end - file_zones_json_start);
|
||||
response->addHeader("Content-Encoding", "gzip");
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
_server.on("/js/app.js", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/javascript", file_app_js_start, file_app_js_end - file_app_js_start);
|
||||
response->addHeader("Content-Encoding", "gzip");
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
_server.onNotFound(std::bind(&WebApiClass::onNotFound, this, _1));
|
||||
_server.begin();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user