Changed JSON parameter loading to the function Changed JSON parameter loading to the function

pull/41/head
Hieromon Ikasamo 6 years ago
parent fea9616f63
commit e068f5d6a0
  1. 2
      examples/HelloWorld/Data/style.json
  2. 25
      examples/HelloWorld/HelloWorld.ino

@ -1,5 +1,5 @@
{
"name" : "Caption",
"type" : "ACText",
"style": "text-align:center;font-family:'Avenir','Corbel','Osaka';color:Green;"
"style": "text-align:center;font-size:24px;font-family:'Impact','Futura',sans-serif;color:tomato;"
}

@ -28,11 +28,17 @@ typedef WebServer WEBServer;
#define HELLO_URI "/hello"
#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");
//AutoConnectAux for the custom Web page.
AutoConnectAux helloPage(HELLO_URI, "Hello", true, { Caption });
AutoConnect portal;
// JSON document loading buffer
String ElementJson;
// Redirects from root to the hello page.
void onRoot() {
WEBServer& webServer = portal.host();
@ -44,17 +50,26 @@ void onRoot() {
// Load the attribute of the element to modify at runtime from external.
String onHello(AutoConnectAux& aux, PageArgument& args) {
File param = SPIFFS.open(PARAM_STYLE, "r");
aux.loadElement(param);
param.close();
aux.loadElement(ElementJson);
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() {
delay(1000);
Serial.begin(115200);
SPIFFS.begin(); // Prepare SPIFFS
loadParam(PARAM_STYLE); // Pre-load the element from JSON.
helloPage.on(onHello); // Register the attribute overwrite handler.
portal.join(helloPage); // Join the hello page.
portal.begin();

Loading…
Cancel
Save