2022-01-10 00:55:04 +01:00
|
|
|
#include "webui.h"
|
2022-01-07 21:02:27 +01:00
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
AsyncWebServer webServer(80);
|
2022-01-09 20:51:16 +01:00
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
const char *PARAM_MESSAGE = "message";
|
2022-01-07 21:02:27 +01:00
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
String processor(const String &var);
|
|
|
|
void WebserverPost_Callback(AsyncWebServerRequest *request);
|
|
|
|
void WebserverNotFound_Callback(AsyncWebServerRequest *request);
|
2022-01-19 22:23:36 +01:00
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
void initWebUI()
|
2022-01-08 03:14:26 +01:00
|
|
|
{
|
2022-02-10 22:33:52 +01:00
|
|
|
if (!LittleFS.begin())
|
2022-01-08 03:14:26 +01:00
|
|
|
{
|
2022-02-10 22:33:52 +01:00
|
|
|
Serial.println("An Error has occurred while mounting LittleFS");
|
|
|
|
return;
|
2022-01-09 20:51:16 +01:00
|
|
|
}
|
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
// Route to load style.css file
|
|
|
|
webServer.serveStatic("/", LittleFS, "/").setDefaultFile("index.htm");
|
|
|
|
webServer.onNotFound(WebserverNotFound_Callback);
|
2022-01-09 20:51:16 +01:00
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
webServer.on("/index.htm", HTTP_GET, [](AsyncWebServerRequest *request)
|
|
|
|
{ request->send(LittleFS, "/index.htm", String(), false, processor); });
|
2022-01-07 21:02:27 +01:00
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
webServer.on("/", HTTP_POST, WebserverPost_Callback);
|
2022-01-09 20:51:16 +01:00
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
webServer.begin();
|
2022-01-07 21:02:27 +01:00
|
|
|
}
|
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
void UpdateWebUI()
|
2022-01-19 22:23:36 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
String processor(const String &var)
|
2022-01-08 03:14:26 +01:00
|
|
|
{
|
2022-01-09 20:51:16 +01:00
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
if (var == "PLACEHOLDER")
|
|
|
|
return "placeholder";
|
2022-01-09 20:51:16 +01:00
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
return String();
|
|
|
|
}
|
2022-01-19 22:23:36 +01:00
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
void WebserverPost_Callback(AsyncWebServerRequest *request)
|
|
|
|
{
|
|
|
|
String message;
|
|
|
|
if (request->hasParam(PARAM_MESSAGE, true))
|
2022-01-19 22:23:36 +01:00
|
|
|
{
|
2022-02-10 22:33:52 +01:00
|
|
|
message = request->getParam(PARAM_MESSAGE, true)->value();
|
|
|
|
Serial.printf("POST: %s", message);
|
2022-01-19 22:23:36 +01:00
|
|
|
}
|
2022-01-08 03:14:26 +01:00
|
|
|
}
|
2022-01-12 01:10:21 +01:00
|
|
|
|
2022-02-10 22:33:52 +01:00
|
|
|
void WebserverNotFound_Callback(AsyncWebServerRequest *request)
|
2022-01-12 01:10:21 +01:00
|
|
|
{
|
2022-02-10 22:33:52 +01:00
|
|
|
request->send(404, "text/plain", "Not found");
|
2022-01-12 01:10:21 +01:00
|
|
|
}
|