55 lines
1.9 KiB
HTML
55 lines
1.9 KiB
HTML
<!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>
|