Initial commit
This commit is contained in:
153
html/app.js
Normal file
153
html/app.js
Normal file
@@ -0,0 +1,153 @@
|
||||
// =========================================================
|
||||
// Tank Monitor - app.js
|
||||
// =========================================================
|
||||
|
||||
const TANK_FULL_PASSWORD = "1234"; // 🔐 CHANGE THIS
|
||||
|
||||
// ===============================
|
||||
// Fetch sensor data and update UI
|
||||
// ===============================
|
||||
async function fetchSensorData() {
|
||||
try {
|
||||
const response = await fetch("/sensor");
|
||||
const data = await response.json();
|
||||
|
||||
// Level
|
||||
const level_mm = data.pressure / 9.810;
|
||||
document.getElementById("level").innerText =
|
||||
level_mm.toFixed(3) + " m";
|
||||
|
||||
|
||||
// Pressure
|
||||
document.getElementById("pressure").innerText =
|
||||
data.pressure.toFixed(3) + " Kpa";
|
||||
|
||||
// Tank % + Liters (robust)
|
||||
const pct = data.tank_percent;
|
||||
const capacity = Number(TANK_CAPACITY_L);
|
||||
|
||||
const percentEl = document.getElementById("percent");
|
||||
|
||||
if (!isNaN(capacity) && capacity > 0) {
|
||||
const liters = (pct / 100) * capacity;
|
||||
percentEl.innerText =
|
||||
`${pct.toFixed(1)} % [${liters.toFixed(0)} L]`;
|
||||
} else {
|
||||
percentEl.innerText =
|
||||
`${pct.toFixed(1)} %`;
|
||||
}
|
||||
|
||||
// CPU temp
|
||||
document.getElementById("cpu").innerText =
|
||||
data.cpu_temp.toFixed(1) + " °C";
|
||||
|
||||
// RSSI: dBm → %
|
||||
let rssiPercent = (data.rssi + 100) * 2;
|
||||
rssiPercent = Math.max(0, Math.min(100, rssiPercent));
|
||||
document.getElementById("rssi").innerText =
|
||||
rssiPercent.toFixed(0) + " %";
|
||||
|
||||
// Free memory → KB
|
||||
document.getElementById("mem").innerText =
|
||||
(data.mem / 1024).toFixed(1) + " KB";
|
||||
|
||||
// Uptime
|
||||
document.getElementById("uptime").innerText =
|
||||
data.uptime;
|
||||
|
||||
updateTankBar(pct);
|
||||
|
||||
// Change footer on html page
|
||||
// data.footer = "Powered by Raspberry Pi Pico W & HX710B - Test"
|
||||
document.getElementById("footer-text").innerText = data.footer;
|
||||
|
||||
|
||||
} catch (err) {
|
||||
console.log("Sensor fetch error:", err);
|
||||
}
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// Tank animation + color scaling
|
||||
// ===============================
|
||||
function updateTankBar(percent) {
|
||||
const fill = document.getElementById("tank-fill");
|
||||
|
||||
percent = Math.max(0, Math.min(100, percent));
|
||||
fill.style.height = percent + "%";
|
||||
fill.style.backgroundColor = tankColor(percent);
|
||||
}
|
||||
|
||||
function tankColor(p) {
|
||||
let r, g, b;
|
||||
|
||||
if (p <= 50) {
|
||||
const t = p / 50;
|
||||
r = 211 + (251 - 211) * t;
|
||||
g = 50 + (192 - 50) * t;
|
||||
b = 47 + (45 - 47) * t;
|
||||
} else {
|
||||
const t = (p - 50) / 50;
|
||||
r = 251 + (76 - 251) * t;
|
||||
g = 192 + (175 - 192) * t;
|
||||
b = 45 + (80 - 45) * t;
|
||||
}
|
||||
|
||||
return `rgb(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)})`;
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// Date & Time
|
||||
// ===============================
|
||||
function updateClock() {
|
||||
const now = new Date();
|
||||
|
||||
document.getElementById("date").innerText =
|
||||
`${now.getFullYear()}-${String(now.getMonth()+1).padStart(2,"0")}-${String(now.getDate()).padStart(2,"0")}`;
|
||||
|
||||
document.getElementById("time").innerText =
|
||||
`${String(now.getHours()).padStart(2,"0")}:${String(now.getMinutes()).padStart(2,"0")}:${String(now.getSeconds()).padStart(2,"0")}`;
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// Theme toggle
|
||||
// ===============================
|
||||
const modeSwitch = document.getElementById("modeSwitch");
|
||||
|
||||
if (localStorage.getItem("theme") === "dark") {
|
||||
document.body.classList.add("dark");
|
||||
if (modeSwitch) modeSwitch.checked = true;
|
||||
}
|
||||
|
||||
if (modeSwitch) {
|
||||
modeSwitch.addEventListener("change", () => {
|
||||
document.body.classList.toggle("dark", modeSwitch.checked);
|
||||
localStorage.setItem("theme", modeSwitch.checked ? "dark" : "light");
|
||||
});
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// Password-protected Tank Full
|
||||
// ===============================
|
||||
function tankFullProtected() {
|
||||
const entered = prompt("Enter password to set Tank FULL:");
|
||||
if (entered !== TANK_FULL_PASSWORD) {
|
||||
alert("❌ Incorrect password");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirm("Confirm: Set tank to FULL?")) return;
|
||||
|
||||
fetch("/tare");
|
||||
}
|
||||
|
||||
window.tankFullProtected = tankFullProtected;
|
||||
|
||||
// ===============================
|
||||
// Start
|
||||
// ===============================
|
||||
setInterval(fetchSensorData, 1000);
|
||||
setInterval(updateClock, 1000);
|
||||
|
||||
fetchSensorData();
|
||||
updateClock();
|
||||
BIN
html/favicon.ico
Normal file
BIN
html/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
287
html/index.html
Normal file
287
html/index.html
Normal file
@@ -0,0 +1,287 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Tank Monitor</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<style>
|
||||
|
||||
/* ======================= */
|
||||
/* THEME VARIABLES */
|
||||
/* ======================= */
|
||||
:root {
|
||||
--bg: #f4f6f8;
|
||||
--text: #000;
|
||||
--card-bg: #ffffff;
|
||||
--accent: #1976d2;
|
||||
--tank-bg: #e0e0e0;
|
||||
--wave: rgba(255,255,255,0.35);
|
||||
--footer: #555;
|
||||
}
|
||||
|
||||
body.dark {
|
||||
--bg: #121212;
|
||||
--text: #e0e0e0;
|
||||
--card-bg: #1f1f1f;
|
||||
--accent: #1e88e5;
|
||||
--tank-bg: #333;
|
||||
--wave: rgba(255,255,255,0.25);
|
||||
--footer: #888;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
transition: background 0.3s, color 0.3s;
|
||||
}
|
||||
|
||||
/* ======================= */
|
||||
/* HEADER + THEME SWITCH */
|
||||
/* ======================= */
|
||||
.header {
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
padding: 15px;
|
||||
text-align: center;
|
||||
font-size: 22px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.theme-toggle {
|
||||
position: absolute;
|
||||
right: 20px;
|
||||
top: 15px;
|
||||
}
|
||||
|
||||
.theme-toggle input {
|
||||
appearance: none;
|
||||
width: 50px;
|
||||
height: 25px;
|
||||
background: #555;
|
||||
border-radius: 50px;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.theme-toggle input:checked {
|
||||
background: #90caf9;
|
||||
}
|
||||
|
||||
.theme-toggle input::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 21px;
|
||||
height: 21px;
|
||||
background: white;
|
||||
border-radius: 50%;
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.theme-toggle input:checked::before {
|
||||
transform: translateX(25px);
|
||||
}
|
||||
|
||||
/* ======================= */
|
||||
/* CONTAINERS + CARDS */
|
||||
/* ======================= */
|
||||
.container {
|
||||
width: 95%;
|
||||
max-width: 900px;
|
||||
margin: auto;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--card-bg);
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.25);
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.card h3 {
|
||||
margin-top: 0;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.stats-block p {
|
||||
margin: 6px 0;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.tank-flex-wrapper {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 30px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* ======================= */
|
||||
/* VERTICAL TANK WAVE */
|
||||
/* ======================= */
|
||||
.tank-container {
|
||||
width: min(100vw, 150px);
|
||||
height: min(75vh, 250px);
|
||||
background: var(--tank-bg);
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
box-shadow: inset 0 0 10px rgba(0,0,0,0.6);
|
||||
transition: width 0.3s, height 0.3s;
|
||||
}
|
||||
|
||||
#tank-fill {
|
||||
width: 100%;
|
||||
height: 0%;
|
||||
background: #4caf50;
|
||||
position: relative;
|
||||
transition: height 1s linear, background-color 1s linear;
|
||||
}
|
||||
|
||||
#tank-fill::before,
|
||||
#tank-fill::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
width: 200%;
|
||||
height: 20px;
|
||||
background: var(--wave);
|
||||
border-radius: 50%;
|
||||
animation: wave 3s infinite linear;
|
||||
}
|
||||
|
||||
#tank-fill::before { top: -5px; }
|
||||
#tank-fill::after {
|
||||
top: -12px;
|
||||
opacity: 0.5;
|
||||
animation-duration: 5s;
|
||||
}
|
||||
|
||||
@keyframes wave {
|
||||
from { transform: translateX(-50%); }
|
||||
to { transform: translateX(0%); }
|
||||
}
|
||||
|
||||
/* ======================= */
|
||||
/* BUTTONS */
|
||||
/* ======================= */
|
||||
button {
|
||||
padding: 12px 20px;
|
||||
background: #e53935;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: #ff5252;
|
||||
}
|
||||
|
||||
.button-row {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.button-row button {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.button-row {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
/* ======================= */
|
||||
/* FOOTER */
|
||||
/* ======================= */
|
||||
.footer {
|
||||
text-align: center;
|
||||
margin-top: 30px;
|
||||
color: var(--footer);
|
||||
font-size: 12px;
|
||||
padding-bottom: 30px;
|
||||
}
|
||||
|
||||
/* Mobile tank adjustment */
|
||||
@media (max-width: 600px) {
|
||||
.tank-container {
|
||||
width: 65px;
|
||||
height: 25vh;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<script src="/app.js" defer></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="header">
|
||||
Tank Monitor
|
||||
<label class="theme-toggle">
|
||||
<input id="modeSwitch" type="checkbox">
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<!-- System Stats + Tank -->
|
||||
<div class="card">
|
||||
<h3>System Stats</h3>
|
||||
|
||||
<div class="tank-flex-wrapper">
|
||||
|
||||
<div class="stats-block">
|
||||
<p><b>Date:</b> <span id="date">--</span></p>
|
||||
<p><b>Time:</b> <span id="time">--</span></p>
|
||||
<p><b>Uptime:</b> <span id="uptime">--</span></p>
|
||||
<p><b>Level:</b> <span id="level">--</span></p>
|
||||
<p><b>Pressure:</b> <span id="pressure">--</span></p>
|
||||
<p><b>Tank Level:</b> <span id="percent">--</span></p>
|
||||
<p><b>CPU Temp:</b> <span id="cpu">--</span></p>
|
||||
<p><b>WiFi RSSI:</b> <span id="rssi">--</span></p>
|
||||
<p><b>Free Memory:</b> <span id="mem">--</span></p>
|
||||
</div>
|
||||
|
||||
<div class="tank-container">
|
||||
<div id="tank-fill"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="card">
|
||||
<h3>Actions</h3>
|
||||
|
||||
<div class="button-row">
|
||||
<!-- <button onclick="fetch('/tare')">Tank Full</button> -->
|
||||
<button onclick="tankFullProtected()">Tank Full</button>
|
||||
<button onclick="fetch('/calibrate')">Calibrate</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="footer" id="footer-text">
|
||||
Powered by Raspberry Pi Pico W & HX710B
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user