72 lines
1.9 KiB
HTML
72 lines
1.9 KiB
HTML
<!doctype html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
|
<meta charset="utf-8">
|
|
<title>Uart controller for esp32</title>
|
|
<link rel="icon" href="favicon.ico" sizes="32x32">
|
|
<style>
|
|
:root {
|
|
--bg: #222;
|
|
--panel: #14171b;
|
|
--danger: #ff3b30;
|
|
--text: #e6eef6;
|
|
}
|
|
html, body {
|
|
height:100%; margin:0;
|
|
background:var(--bg);
|
|
color:var(--text);
|
|
font-family: Inter,system-ui, Segoe UI, Roboto, Helvetica,Arial;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="app">
|
|
<header class="app-header"></header>
|
|
<div class="content"></div>
|
|
<footer class="footer"> <div class="error"></div></footer>
|
|
</div>
|
|
<script src="tools.js"></script>
|
|
<script>
|
|
let ws = null;
|
|
const retryDelay = 1000; // 1 seconde
|
|
|
|
function sendCommand(payload) {
|
|
try {
|
|
if (!ws || ws.readyState !== WebSocket.OPEN)
|
|
return;
|
|
ws.send(JSON.stringify(payload));
|
|
} catch (e) {}
|
|
}
|
|
|
|
function connect() {
|
|
ws = new WebSocket("ws://" + location.host + "/ws");
|
|
|
|
ws.onopen = () => {
|
|
sendCommand({action: 'status'});
|
|
};
|
|
ws.onclose = (e) => {
|
|
console.log("WS closed", e.code, e.reason);
|
|
setTimeout(connect, retryDelay);
|
|
};
|
|
ws.onerror = (e) => {
|
|
console.log("WS error", e);
|
|
const data = JSON.parse(e.data);
|
|
s('.error').textContent = data.error;
|
|
ws.close();
|
|
};
|
|
ws.onmessage = (event) => {
|
|
try {
|
|
const data = JSON.parse(event.data);
|
|
//console.log("Réponse JSON : ", data);
|
|
} catch (e) {
|
|
//console.log("Message error: ", e);
|
|
s('.error').textContent = e;
|
|
}
|
|
};
|
|
}
|
|
connect();
|
|
</script>
|
|
</body>
|
|
</html>
|