Software_and_hardware/Версия_3.0/templates/index.html

55 lines
1.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>