|
|
@ -28,11 +28,17 @@ typedef WebServer WEBServer; |
|
|
|
#define HELLO_URI "/hello" |
|
|
|
#define HELLO_URI "/hello" |
|
|
|
#define PARAM_STYLE "/style.json" |
|
|
|
#define PARAM_STYLE "/style.json" |
|
|
|
|
|
|
|
|
|
|
|
// Declare AutoConnectElements and AutoConnectAux for the custom Web page.
|
|
|
|
// Declare AutoConnectText with only a value.
|
|
|
|
|
|
|
|
// Qualify the Caption by reading style attributes from the SPIFFS style.json file.
|
|
|
|
ACText(Caption, "Hello, world"); |
|
|
|
ACText(Caption, "Hello, world"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//AutoConnectAux for the custom Web page.
|
|
|
|
AutoConnectAux helloPage(HELLO_URI, "Hello", true, { Caption }); |
|
|
|
AutoConnectAux helloPage(HELLO_URI, "Hello", true, { Caption }); |
|
|
|
AutoConnect portal; |
|
|
|
AutoConnect portal; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// JSON document loading buffer
|
|
|
|
|
|
|
|
String ElementJson; |
|
|
|
|
|
|
|
|
|
|
|
// Redirects from root to the hello page.
|
|
|
|
// Redirects from root to the hello page.
|
|
|
|
void onRoot() { |
|
|
|
void onRoot() { |
|
|
|
WEBServer& webServer = portal.host(); |
|
|
|
WEBServer& webServer = portal.host(); |
|
|
@ -44,17 +50,26 @@ void onRoot() { |
|
|
|
|
|
|
|
|
|
|
|
// Load the attribute of the element to modify at runtime from external.
|
|
|
|
// Load the attribute of the element to modify at runtime from external.
|
|
|
|
String onHello(AutoConnectAux& aux, PageArgument& args) { |
|
|
|
String onHello(AutoConnectAux& aux, PageArgument& args) { |
|
|
|
File param = SPIFFS.open(PARAM_STYLE, "r"); |
|
|
|
aux.loadElement(ElementJson); |
|
|
|
aux.loadElement(param); |
|
|
|
|
|
|
|
param.close(); |
|
|
|
|
|
|
|
return String(); |
|
|
|
return String(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load the element from specified file in SPIFFS.
|
|
|
|
|
|
|
|
void loadParam(const char* fileName) { |
|
|
|
|
|
|
|
SPIFFS.begin(); |
|
|
|
|
|
|
|
File param = SPIFFS.open(fileName, "r"); |
|
|
|
|
|
|
|
if (param) { |
|
|
|
|
|
|
|
ElementJson = param.readString(); |
|
|
|
|
|
|
|
param.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
SPIFFS.end(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void setup() { |
|
|
|
void setup() { |
|
|
|
delay(1000); |
|
|
|
delay(1000); |
|
|
|
Serial.begin(115200); |
|
|
|
Serial.begin(115200); |
|
|
|
SPIFFS.begin(); // Prepare SPIFFS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadParam(PARAM_STYLE); // Pre-load the element from JSON.
|
|
|
|
helloPage.on(onHello); // Register the attribute overwrite handler.
|
|
|
|
helloPage.on(onHello); // Register the attribute overwrite handler.
|
|
|
|
portal.join(helloPage); // Join the hello page.
|
|
|
|
portal.join(helloPage); // Join the hello page.
|
|
|
|
portal.begin(); |
|
|
|
portal.begin(); |
|
|
|