Interface data storage in PROGMEM (#71)

Adds a webpack plugin to package interface as PROGMEM into a header file in the framework.
Adds a build flag to optionally enable serving from PROGMEM or SPIFFS as required
Adds documentation changes to describe changes
This commit is contained in:
rjwats
2019-12-29 17:54:12 +00:00
committed by GitHub
parent 14f50c1e31
commit bcfeef8004
20 changed files with 324 additions and 85 deletions

View File

@ -13,8 +13,8 @@
#define DNS_PORT 53
#define AP_DEFAULT_SSID "ssid"
#define AP_DEFAULT_PASSWORD "password"
#define AP_DEFAULT_SSID "ESP8266-React"
#define AP_DEFAULT_PASSWORD "esp-react"
#define AP_SETTINGS_FILE "/config/apSettings.json"
#define AP_SETTINGS_SERVICE_PATH "/rest/apSettings"

View File

@ -13,13 +13,37 @@ ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs) :
_ntpStatus(server, &_securitySettingsService),
_apStatus(server, &_securitySettingsService),
_systemStatus(server, &_securitySettingsService) {
#ifdef PROGMEM_WWW
// Serve static resources from PROGMEM
WWWData::registerRoutes(
[server, this](const String& uri, const String& contentType, const uint8_t* content, size_t len) {
ArRequestHandlerFunction requestHandler = [contentType, content, len](AsyncWebServerRequest* request) {
AsyncWebServerResponse* response = request->beginResponse_P(200, contentType, content, len);
response->addHeader("Content-Encoding", "gzip");
request->send(response);
};
server->on(uri.c_str(), HTTP_GET, requestHandler);
// Serving non matching get requests with "/index.html"
// OPTIONS get a straight up 200 response
if (uri.equals("/index.html")) {
server->onNotFound([requestHandler](AsyncWebServerRequest* request) {
if (request->method() == HTTP_GET) {
requestHandler(request);
} else if (request->method() == HTTP_OPTIONS) {
request->send(200);
} else {
request->send(404);
}
});
}
});
#else
// Serve static resources from /www/
server->serveStatic("/js/", SPIFFS, "/www/js/");
server->serveStatic("/css/", SPIFFS, "/www/css/");
server->serveStatic("/fonts/", SPIFFS, "/www/fonts/");
server->serveStatic("/app/", SPIFFS, "/www/app/");
server->serveStatic("/favicon.ico", SPIFFS, "/www/favicon.ico");
// Serving all other get requests with "/www/index.htm"
// OPTIONS get a straight up 200 response
server->onNotFound([](AsyncWebServerRequest* request) {
@ -31,6 +55,7 @@ ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs) :
request->send(404);
}
});
#endif
// Disable CORS if required
#if defined(ENABLE_CORS)

View File

@ -4,9 +4,9 @@
#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#include <SPIFFS.h>
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
@ -26,6 +26,10 @@
#include <WiFiSettingsService.h>
#include <WiFiStatus.h>
#ifdef PROGMEM_WWW
#include <WWWData.h>
#endif
class ESP8266React {
public:
ESP8266React(AsyncWebServer* server, FS* fs);
@ -52,6 +56,7 @@ class ESP8266React {
NTPStatus _ntpStatus;
APStatus _apStatus;
SystemStatus _systemStatus;
};
#endif

View File

@ -17,6 +17,9 @@ void SecuritySettingsService::readFromJsonObject(JsonObject& root) {
for (JsonVariant user : root["users"].as<JsonArray>()) {
_users.push_back(User(user["username"], user["password"], user["admin"]));
}
} else {
_users.push_back(User(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_USERNAME, true));
_users.push_back(User(DEFAULT_GUEST_USERNAME, DEFAULT_GUEST_USERNAME, false));
}
}

View File

@ -4,6 +4,9 @@
#include <AdminSettingsService.h>
#include <SecurityManager.h>
#define DEFAULT_ADMIN_USERNAME "admin"
#define DEFAULT_GUEST_USERNAME "guest"
#define SECURITY_SETTINGS_FILE "/config/securitySettings.json"
#define SECURITY_SETTINGS_PATH "/rest/securitySettings"