Repository navigation
Expand file tree
/
Copy pathinterface.html
More file actions
64 lines (53 loc) · 2.09 KB
/
Copy pathinterface.html
File metadata and controls
64 lines (53 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
<title>WebSocket Test</title>
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.1.2/socket.io.js"></script>
</head>
<body data-bs-theme="dark">
<div class="card m-2">
<div class='card-body' id="antennas">
<h5 class="card-title">RemoteBox</h5>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function() {
var pollStatus = setInterval(getStatus, 1000)
})
const socket = io.connect('http://localhost:3001'); // Replace 'localhost' with your server's hostname or IP address
socket.on('connect', () => {
console.log('Connected to WebSocket server');
});
socket.on('disconnect', () => {
console.log('Disconnected from WebSocket server');
});
socket.on('status', (data) => {
// data = { 1: [bool x8], 2: [bool x8] }, one key per radio
const $box = $("#antennas")
Object.keys(data).forEach((radio) => {
let $row = $(`#radio${radio}`)
if (!$row.length) {
$row = $(`<div id="radio${radio}" class="mb-2"><div class="small text-muted">Radio ${radio}</div></div>`)
data[radio].forEach((_, i) => {
$row.append(`<button type="button" class="btn btn-secondary me-1" data-radio="${radio}" data-ant="${i}">ANT-${i + 1}</button>`)
})
$box.append($row)
}
$row.find("button").each(function () {
const on = data[radio][this.dataset.ant]
$(this).toggleClass("btn-success", on).toggleClass("btn-secondary", !on)
})
})
});
function getStatus() {
socket.emit('get-status');
}
$(document).on("click", "#antennas button", function () {
// radio, antenna index (0..7), on
socket.emit('set-antenna', Number(this.dataset.radio), Number(this.dataset.ant), true)
})
</script>