Доделал последнюю версию

This commit is contained in:
2025-02-15 02:16:43 +03:00
parent 465df94f07
commit b156930709
15 changed files with 622 additions and 87 deletions
+54
View File
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modbus Status</title>
<style>
#statusCircle {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: gray;
margin: 20px;
}
#portInfo {
margin-top: 20px;
}
</style>
</head>
<body>
<h1>Modbus Slave Status</h1>
<div id="portInfo">Номер порта: <span id="portNumber">Не подключено</span></div>
<div id="statusCircle"></div>
<script>
async function fetchStatus() {
try {
const response = await fetch('/status');
const data = await response.json();
if (data.error) {
console.log('Ошибка: ', data.error);
} else {
document.getElementById("portNumber").innerText = data.port;
const statusCircle = document.getElementById("statusCircle");
// Обновляем цвет круга в зависимости от состояния пина
if (data.pinState === 1) {
statusCircle.style.backgroundColor = "green"; // Зеленый если состояние 7 пина HIGH
} else {
statusCircle.style.backgroundColor = "red"; // Красный если состояние 7 пина LOW
}
}
} catch (error) {
console.log('Ошибка при получении данных: ', error);
}
}
// Получать данные каждую секунду
setInterval(fetchStatus, 1000);
fetchStatus(); // Вызвать сразу для начальной загрузки
</script>
</body>
</html>