diff --git a/data/index.html b/data/index.html
new file mode 100644
index 0000000..a67ac0f
--- /dev/null
+++ b/data/index.html
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+ ~LIST~
+
+
+
\ No newline at end of file
diff --git a/include/ESPTemplateProcessor.h b/include/ESPTemplateProcessor.h
new file mode 100644
index 0000000..264507c
--- /dev/null
+++ b/include/ESPTemplateProcessor.h
@@ -0,0 +1,116 @@
+#ifndef ESP_TEMPLATE_PROCESSOR_H
+#define ESP_TEMPLATE_PROCESSOR_H
+
+#ifdef ESP8266
+#define WebServer ESP8266WebServer
+#include
+#else
+#include
+#endif
+
+#include
+
+typedef String ProcessorCallback(const String& key);
+
+class ESPTemplateProcessor {
+ public:
+ ESPTemplateProcessor(WebServer& _server) :
+ server(_server)
+ {
+ }
+
+ bool send(const String& filePath, ProcessorCallback& processor, char bookend = '~', bool silentSerial = false)
+ {
+ // Open file.
+ if(!LittleFS.exists(filePath)) {
+ if(!silentSerial) {
+ Serial.print("Cannot process "); Serial.print(filePath); Serial.println(": Does not exist.");
+ }
+ return false;
+ }
+
+ File file = LittleFS.open(filePath, "r");
+ if (!file) {
+ if(!silentSerial) {
+ Serial.print("Cannot process "); Serial.print(filePath); Serial.println(": Failed to open.");
+ }
+ return false;
+ }
+
+ server.setContentLength(CONTENT_LENGTH_UNKNOWN);
+ server.sendHeader("Content-Type","text/html",true);
+ server.sendHeader("Cache-Control","no-cache");
+ server.send(200);
+ //server.sendContent()
+
+ // Process!
+ static const uint16_t MAX = 100;
+ String buffer;
+ int bufferLen = 0;
+ String keyBuffer;
+ int val;
+ char ch;
+ while ((val = file.read()) != -1) {
+ ch = char(val);
+
+ // Lookup expansion.
+ if (ch == bookend) {
+ // Clear out buffer.
+ server.sendContent(buffer);
+ buffer = "";
+ bufferLen = 0;
+
+ // Process substitution.
+ keyBuffer = "";
+ bool found = false;
+ while (!found && (val = file.read()) != -1) {
+ ch = char(val);
+ if (ch == bookend) {
+ found = true;
+ } else {
+ keyBuffer += ch;
+ }
+ }
+
+ // Check for bad exit.
+ if (val == -1 && !found) {
+ if(!silentSerial) {
+ Serial.print("Cannot process "); Serial.print(filePath); Serial.println(": Unable to parse.");
+ }
+ return false;
+ }
+
+ // Get substitution
+ String processed = processor(keyBuffer);
+ if(!silentSerial) {
+ Serial.print("Lookup '"); Serial.print(keyBuffer); Serial.print("' received: "); Serial.println(processed);
+ }
+ server.sendContent(processed);
+ } else {
+ bufferLen++;
+ buffer += ch;
+ if (bufferLen >= MAX) {
+ server.sendContent(buffer);
+ bufferLen = 0;
+ buffer = "";
+ }
+ }
+ }
+
+ if (val == -1) {
+ server.sendContent(buffer);
+ server.sendContent("");
+ return true;
+ } else {
+ if(!silentSerial) {
+ Serial.print("Failed to process '"); Serial.print(filePath); Serial.println("': Didn't reach the end of the file.");
+ }
+ }
+ }
+
+
+ private:
+ WebServer &server;
+};
+
+#endif
\ No newline at end of file
diff --git a/platformio.ini b/platformio.ini
index 166f854..9e0da9b 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -11,6 +11,7 @@
[env:wemos-d1]
platform = espressif8266
board = d1
+board_build.filesystem = littlefs
upload_speed = 460800
framework = arduino
lib_deps =
diff --git a/src/busylight.cpp b/src/busylight.cpp
index d5a3f5a..8d85afd 100644
--- a/src/busylight.cpp
+++ b/src/busylight.cpp
@@ -12,7 +12,9 @@ WiFiClientSecure wifi_secure;
char current_state[20];
#ifdef ENABLE_WEBSERVER
+#include
#include
+#include "ESPTemplateProcessor.h"
ESP8266WebServer server;
#endif
@@ -71,7 +73,7 @@ bool Switch_Status(String name) {
Serial.println("Switching to " + name);
for(int j=0; jBusylight";
- for(int j=0; j");
- strcat(buffer, statuses[j].name);
- strcat(buffer, "
");
+String ProcessIndexPage(const String& var) {
+ Serial.println(current_state);
+ if (var == "LIST") {
+ String buffer;
+ for(int j=0; j";
+ buffer += statuses[j].name;
+ buffer += "
";
+ }
+ return buffer;
}
- strcat(buffer, "