-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathv8mqtt_test.js
45 lines (29 loc) · 848 Bytes
/
v8mqtt_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
function myOnMqttMessage(topic, payload) {
console.error(topic)
console.error(payload)
}
function main() {
console.log("<b>mqtt test</b>");
var options = {};
//options.username = "mqtt";
//options.password = "secret";
//options.useSSL = false;
options.cleanSession = true;
//The certificate authority file (PEM FORMAT) has to be placed in the jstest directory.
//options.certFile = "MyRootCA.pem";
mqtt.connect(
"tcp://test.mosquitto.org:1883", //brokerUrl
"js1Client1", //clientId
JSON.stringify(options));
mqtt.onMqttMessage = myOnMqttMessage;
var payload = {
t : "hello mqtt",
b : true,
ts : new Date()
};
mqtt.subscribe("test/mqtt", 2);
mqtt.publish("test/mqtt", JSON.stringify(payload), 2, true);
_msleep(150)
mqtt.disconnect();
return "";
};