forked from hardillb/d3-MQTT-Topic-Tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
89 lines (77 loc) · 2.24 KB
/
index.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html>
<head>
<title>TopicTreeMQTT</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script type="text/javascript" src="js/d3.min.js"></script>
<script type="text/javascript" src="js/topic-tree.js"></script>
<script type="text/javascript" src="js/socket.io.min.js"></script>
<style type="text/css">
.node circle {
cursor: pointer;
fill: #fff;
stroke: steelblue;
stroke-width: 1.5px;
}
.node text {
font-size: 11px;
}
path.link {
fill: none;
stroke: #ccc;
stroke-width: 1.5px;
}
.popup rect {
fill: grey;
stroke: black;
stroke-width: 1.5px;
opacity: 1;
fill-opacity: 1;
}
.popup text {
fill: white;
font-weight: bold;
}
</style>
</head>
<body>
<div id="body" style="width:1280px; height:800px; border=1px;">
</div>
<script type="text/javascript">
setup("body");
var port = 3000;
var host = (window.location.hostname) ? "http://" + window.location.hostname + ":" + port : "http://192.168.0.175:" + port
//Connect to socket.io server
var socket = io.connect(host);
socket.on('connect', function () {
socket.on('mqtt', function (msg) {
addNode(msg.topic, msg.payload);
});
//Topic subscriptions
socket.emit('subscribe',
{topic: 'home/#'},
{topic: 'weather/#'}
);
});
// setup("body");
// var client = new Messaging.Client(document.location.hostname,1883,"web" + new Date().getTime());
// client.onMessageArrived = onMessage;
// client.onconnectionlost = onDisconnect;
// function onConnect(){
// client.subscribe('#',onMessage);
// console.log("mqtt connected");
// }
// console.log("bar");
// client.connect({onSuccess:onConnect});
// function onMessage(message) {
// //console.log(message.topic + "- " + message.payload);
// addNode(message.destinationName, message.payloadString);
// }
// function onDisconnect(reason) {
// console.log("disconnected - " + reason);
// alert("disconnected - " + reason);
// }
</script>
</body>
</html>