-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMQTTClient.js
More file actions
33 lines (28 loc) · 830 Bytes
/
Copy pathMQTTClient.js
File metadata and controls
33 lines (28 loc) · 830 Bytes
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
/**
* Created by HP on 12/14/2016.
*/
var mqtt = require('mqtt');
var options = {
clientId: '24234efsdfx'
//username: 'virtual',
//password: 'virtual'
};
var client = mqtt.connect('mqtt://45.55.91.141:1883', options);
// var client = mqtt.connect('mqtt://broker.hivemq.com:1883', options);
client.on('connect', function () {
client.subscribe('ss12-tech');
});
setInterval(function () {
var a = {
"timestamp": 2323,
"temp": Math.floor((Math.random() * 100 + 1)),
"humid":Math.floor((Math.random() * 200 + 1)),
"foodStatus": Math.floor((Math.random() * 50 + 1)),
"compartment_id": "ESP-03"
};
var as = JSON.stringify(a);
client.publish('ss12-tech', as)
}, 1000);
client.on('message', function (topic, message) {
console.log(message.toString());
});