-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.html
59 lines (48 loc) · 2.52 KB
/
interface.html
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
<!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/[email protected]/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>
<button type="button" onclick=setAntenna(this.dataset.ant) class="btn btn-secondary" data-ant='1' id='ant1'>ANT-1</button>
<button type="button" onclick=setAntenna(this.dataset.ant) class="btn btn-secondary" data-ant='2' id='ant2'>ANT-2</button>
<button type="button" onclick=setAntenna(this.dataset.ant) class="btn btn-secondary" data-ant='3' id='ant3'>ANT-3</button>
<button type="button" onclick=setAntenna(this.dataset.ant) class="btn btn-secondary" data-ant='4' id='ant4'>ANT-4</button>
<button type="button" onclick=setAntenna(this.dataset.ant) class="btn btn-secondary" data-ant='5' id='ant5'>ANT-5</button>
<button type="button" onclick=setAntenna(this.dataset.ant) class="btn btn-secondary" data-ant='6' id='ant6'>ANT-6</button>
<button type="button" onclick=setAntenna(this.dataset.ant) class="btn btn-secondary" data-ant='7' id='ant7'>ANT-7</button>
<button type="button" onclick=setAntenna(this.dataset.ant) class="btn btn-secondary" data-ant='8' id='ant8'>ANT-8</button>
</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) => {
console.log('Received status from server:', data);
const activeAntenna = data.indexOf(1)
$(".btn").removeClass("btn-success").addClass("btn-secondary")
$(`button[data-ant=${activeAntenna+1}]`).removeClass("btn-secondary").addClass('btn-success');
});
function getStatus() {
socket.emit('get-status');
}
function setAntenna(idx) {
socket.emit('set-antenna', 1, idx, 1); // trx, antenna, on. Defaults to trx1
}
</script>