Initial project commit

This commit is contained in:
2026-08-08 20:58:06 -06:00
commit ea34c399d7
18 changed files with 1039 additions and 0 deletions
+161
View File
@@ -0,0 +1,161 @@
#include "web_service.h"
#define FIRMWARE_VERSION "1.0.0"
WebService::WebService()
:
Service("Web", 10),
server(80)
{
}
String formatUptime() {
unsigned long seconds = millis() / 1000;
unsigned long days = seconds / 86400;
seconds %= 86400;
unsigned long hours = seconds / 3600;
seconds %= 3600;
unsigned long minutes = seconds / 60;
seconds %= 60;
char buffer[64];
snprintf(buffer, sizeof(buffer),
"%lu days %02lu:%02lu:%02lu",
days, hours, minutes, seconds);
return String(buffer);
}
String ROOT_HTML = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ESP32 Dashboard</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
background: #111;
color: white;
}
.card {
background: #222;
padding: 25px;
margin: auto;
width: 80%;
max-width: 400px;
border-radius: 15px;
}
h1 {
color: #00ff99;
}
#uptime {
font-size: 28px;
margin-top: 20px;
}
</style>
<script>
function updateUptime() {
fetch('/uptime')
.then(response => response.text())
.then(data => {
document.getElementById("uptime").innerHTML = data;
});
}
setInterval(updateUptime, 1000);
window.onload = updateUptime;
</script>
<script>
function getVersion() {
fetch('/version')
.then(response => response.text())
.then(data => {
document.getElementById("firmware_version").innerHTML = data;
});
}
window.onload = getVersion;
</script>
</head>
<body>
<div class="card">
<h1>ESP32 Dashboard OTA</h1>
<p>Device uptime:</p>
<div id="uptime">Loading...</div>
</div>
<footer>
<div id="firmware_version">Loading...</div>
</footer>
</body>
</html>
)rawliteral";
// server.send(200, "text/html", html);
// }
//
// void handleUptime() {
// server.send(200, "text/plain", formatUptime());
// }
//
// void handleVersion() {
// server.send(200, "text/plain", FIRMWARE_VERSION);
// }
//
void WebService::begin() {
// Root path
server.on("/", [this](){
server.send(
200,
"text/html",
ROOT_HTML
);
});
// Version path
server.on("/version", [this](){
server.send(
200,
"text/plain",
FIRMWARE_VERSION
);
});
// Uptime path
server.on("/uptime", [this]() {
server.send(
200,
"text/plain",
formatUptime()
);
});
server.begin();
Serial.println("Web server started");
}
void WebService::update()
{
server.handleClient();
}