parent
9c946b60bb
commit
fc83f34155
@ -0,0 +1,83 @@ |
|||||||
|
/*
|
||||||
|
HelloWorld.ino, Example for the AutoConnect library. |
||||||
|
Copyright (c) 2019, Hieromon Ikasamo |
||||||
|
https://github.com/Hieromon/AutoConnect
|
||||||
|
|
||||||
|
This software is released under the MIT License. |
||||||
|
https://opensource.org/licenses/MIT
|
||||||
|
*/ |
||||||
|
/*
|
||||||
|
To experience this example, upload the JSON file which is style.json |
||||||
|
from the data folder. Its file contains the attributes for the Caption |
||||||
|
of AutoConnectText. You can change the elements for your realization. |
||||||
|
*/ |
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP8266) |
||||||
|
#include <ESP8266WiFi.h> |
||||||
|
#include <ESP8266WebServer.h> |
||||||
|
typedef ESP8266WebServer WEBServer; |
||||||
|
#elif defined(ARDUINO_ARCH_ESP32) |
||||||
|
#include <WiFi.h> |
||||||
|
#include <WebServer.h> |
||||||
|
#include <SPIFFS.h> |
||||||
|
typedef WebServer WEBServer; |
||||||
|
#endif |
||||||
|
#include <FS.h> |
||||||
|
#include <AutoConnect.h> |
||||||
|
|
||||||
|
#define HELLO_URI "/hello" |
||||||
|
#define PARAM_STYLE "/style.json" |
||||||
|
|
||||||
|
// Declare AutoConnectText with only a value.
|
||||||
|
// Qualify the Caption by reading style attributes from the SPIFFS style.json file.
|
||||||
|
ACImage(Caption, "iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAgVBMVEX///8AAAIAAAC4uLjv7+/Ly8tAQEGRkZHX19ccHB0ODg/r6+u/v7+FhYbh4eGurq75+fl3d3htbW3d3d2oqKigoKCIiIg3Nze6urqYmJjOzs4vLzDa2tp9fX2ysrNoaGkYGBlSUlNiYmIjIyRcXFxNTU4qKis7OzwaGhohISJGRkepVHx7AAAL40lEQVR4nO2d63riIBCGI2rjJp7qWVu1ta3d9v4vcEMIZIYAOZOmy/djn22MhFdggAEmnufk5OTUupaX4W/WZemNyO/WKCIc/GY5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CliaEBZPTEuDuN0PvPDb1gxkfpbhUeJNEWULw7tc8a/anUI8fDTI/gzylKSUXngr7YUsToq0Y5h4J3FnAVWOS3XV8uJ3G6EWbgBtNI+8Cskt4KdoQj8VtUp5+6I4h8FbiulvdLe/6gsNNQ3uHlbToEFIny4STYoUI26vJ21FEtndfgoOd+vVB5DCte1zBNiHsErUtLIA3lc6VJOv7vGEhaua2aKZc+0CGdcJnWAMHKkQ0Ua4QB0GS/fMWZwSQHeSDEWkTRZjxtZVStVNB+GietKlk8oYAB1W7ivCwSZSeViV+9OdwXGYzUjXCZzzcD8C7DU83aSW/6tHEq8HXRu7tjbwTbaQFDLKfLQ6Hw3Yl78cotaUG6tE0My7hEG7khGX602a2m1Q/95Uz9S9+3qryKdmbOQdJPt6qNsJ1XvKFd81VP8tdALE6YPoCc23abXmigIwtheaB7KuPuOe5hEUtWJ2YCpucrYm15r25P1/RcUStuBjzvTYfpO7xYHMNKbGzs2b0FhogSpGT6OK5boyFMzGp9f4w1fAh0wVGmjVwdnY5mepUZnTaQJyo+fYV/bxfj81HWKihhuK1zacbfxfJ35yaC8DTjFzsy/7LEfZfjrD/coT9lyPsvxxh/+UI+y9H2H85wv7LEfZf/xXh/jT+hTo9CsLf/8bj36z/hPB3a+QtL8PfrEaD4Ts5OTlp9A9tuM3Sf39ZwAAAAABJRU5ErkJggg=="); |
||||||
|
|
||||||
|
//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(); |
||||||
|
webServer.sendHeader("Location", String("http://") + webServer.client().localIP().toString() + String(HELLO_URI)); |
||||||
|
webServer.send(302, "text/plain", ""); |
||||||
|
webServer.client().flush(); |
||||||
|
webServer.client().stop(); |
||||||
|
} |
||||||
|
|
||||||
|
// Load the attribute of the element to modify at runtime from external.
|
||||||
|
String onHello(AutoConnectAux& aux, PageArgument& args) { |
||||||
|
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); |
||||||
|
|
||||||
|
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(); |
||||||
|
|
||||||
|
WEBServer& webServer = portal.host(); |
||||||
|
webServer.on("/", onRoot); // Register the root page redirector.
|
||||||
|
} |
||||||
|
|
||||||
|
void loop() { |
||||||
|
portal.handleClient(); |
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
{ |
||||||
|
"name" : "Caption", |
||||||
|
"type" : "ACImage", |
||||||
|
"style": "text-align:center;font-size:24px;font-family:'Impact','Futura',sans-serif;color:tomato;" |
||||||
|
} |
Loading…
Reference in new issue