-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwss_test.js
53 lines (39 loc) · 1023 Bytes
/
wss_test.js
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
"use strict"
var path = require("path")
var fs = require("fs")
var mqtt = require("mqtt")
var Url = require("url")
var HOSTNAME = "wss://10.238.100.170/mqtt"
var PORT = 8084
var CLIENT_ID = "wss_test"
var USERNAME = "root"
var PASSWORD = "12345"
var CERT = fs.readFileSync("client.cert")
var KEY = fs.readFileSync("client-key.pem")
var url = Url.parse(HOSTNAME)
var options = {
servername: url.hostname,
username: USERNAME,
password: PASSWORD,
clientId: CLIENT_ID,
port: PORT,
cert: CERT,
key: KEY,
resubscribe: false,
rejectUnauthorized: false
}
var client = mqtt.connect(url, options)
client.on("connect", function (packet) {
console.log("connected")
})
client.on('error', function (err) {
console.log(err)
})
client.on("message", function (topic, message) {
console.log(message)
})
client.subscribe("messages")
client.publish("messages", "Current time is: " + new Date())
setTimeout(function () {
console.log('Blah blah blah blah extra-blah');
}, 30000)