-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.html
49 lines (49 loc) · 1.24 KB
/
test.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
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Andreas Heine</title>
</head>
<body>
<div id="content"> </div>
<script>
var content = {}
let data
function connect() {
let url = "ws://127.0.0.1:8000";
let s = new WebSocket(url);
s.onopen = function(event) {
console.log(event);
}
s.onclose = function(event) {
console.log(event);
setTimeout(function() {
connect();
}, 2000);
}
s.onerror = function(event) {
console.log(event);
}
s.onmessage = function(event){
data = JSON.parse(event.data);
//console.log(data);
if (data.topic == "datachange notification"){
content[data.payload.node] = {
value: data.payload.value,
data: data.payload.data,
};
}
if (data.topic == "event notification"){
content["Event"] = data;
}
if (data.topic == "status change notification"){
content["Status"] = data;
}
document.getElementById("content").innerHTML = JSON.stringify(content);
}
}
connect();
</script>
</body>
</html>