-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisconnect.html
77 lines (58 loc) · 2.04 KB
/
disconnect.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HILIGHT</title>
<script src="vendors/mqttws31.min.js" type="text/javascript"></script>
<script>
//var wsbroker = "127.0.0.1"; //mqtt websocket enabled broker
var wsbroker = "192.168.0.39"; //mqtt websocket enabled broker
//var wsbroker = "192.168.0.53"; //mqtt websocket enabled broker
var wsport = 9001; // port for above
var client;
function connectClient() {
client = new Paho.MQTT.Client(wsbroker, wsport, "myclientid_" + parseInt(Math.random() * 100, 10));
//console.log(clientIndex + "!!!");
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost:" + responseObject.errorMessage);
}
}
// called when a message arrives
function onMessageArrived(message) {
}
}
var options = {
timeout: 300,
onSuccess: function() {
socketArray.push(client);
console.log("mqtt connected");
// Connection succeeded; subscribe to our topic, you can add multile lines of these
client.subscribe(topic, {
qos: 0
});
//use the below if you want to publish to a topic on connect
// message = new Paho.MQTT.Message("Hello");
// message.destinationName = "/World";
// client.send(message);
},
onFailure: function(message) {
console.log("Connection failed: " + message.errorMessage);
}
};
// connect the client
client.connect(options);
setTimeout(function(){
client.disconnect();
},2000);
</script>
</head>
<body>
</body>
</html>