69 lines
1.7 KiB
C
69 lines
1.7 KiB
C
|
#pragma once
|
||
|
|
||
|
#include "util.h"
|
||
|
|
||
|
static ESP8266WebServer webServer(80);
|
||
|
|
||
|
// use an anonymous namespace for the module's "private" methods
|
||
|
// this prevents the methods from ending up in the global namespace
|
||
|
namespace {
|
||
|
void handleNotFound() {
|
||
|
webServer.send(404, "text/plain", "urm... nope");
|
||
|
}
|
||
|
|
||
|
void handleIndex() {
|
||
|
String htmlText = R"(
|
||
|
<!DOCTYPE html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>LED Marquee Sign Controller</title>
|
||
|
</head>
|
||
|
|
||
|
<body>
|
||
|
<h1>LED Marquee Sign Controller</h1>
|
||
|
<form action="/" method="post">
|
||
|
<fieldset>
|
||
|
<div>
|
||
|
<label for="text">Text to send:</label>
|
||
|
<input type="text" name="text">
|
||
|
</div>
|
||
|
|
||
|
<div>
|
||
|
<label for="bright">Bright mode</label>
|
||
|
<input type="checkbox" name="bright">
|
||
|
</div>
|
||
|
|
||
|
<div>
|
||
|
<button>Send</button>
|
||
|
</div>
|
||
|
</fieldset>
|
||
|
</form>
|
||
|
</body>
|
||
|
</html>
|
||
|
)";
|
||
|
webServer.send(200, "text/html", htmlText);
|
||
|
}
|
||
|
|
||
|
void handleFormSend() {
|
||
|
sendTextToSign("HELLO FORM");
|
||
|
|
||
|
// redirect back to root page
|
||
|
webServer.sendHeader("Location", "/");
|
||
|
webServer.send(303);
|
||
|
}
|
||
|
|
||
|
// RESTful API endpoint -- returns a proper status code rather than a redirect
|
||
|
void handleApiSend() {
|
||
|
sendTextToSign("HELLO API");
|
||
|
webServer.send(200, "text/plain", "ok");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void configureWebServer() {
|
||
|
webServer.onNotFound(handleNotFound);
|
||
|
|
||
|
webServer.on("/", HTTPMethod::HTTP_GET, handleIndex);
|
||
|
webServer.on("/", HTTPMethod::HTTP_POST, handleFormSend);
|
||
|
webServer.on("/send", HTTPMethod::HTTP_POST, handleApiSend);
|
||
|
}
|