-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmqtt_maxcube.js
35 lines (26 loc) · 926 Bytes
/
mqtt_maxcube.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
var MaxCube = require('../maxcube');
var mqtt = require('mqtt')
var myMaxCube = new MaxCube('192.168.1.101', '62910');
client = mqtt.createClient(1883, 'localhost');
client.subscribe('maxcube-control');
myMaxCube.once('connected', function (cubeStatus) {
console.log(cubeStatus);
client.subscribe('maxcube-control');
client.on('message', function (topic, message) {
console.log(message);
var address = message.split(" ")[0];
var temp = message.split(" ")[1];
console.log("setting "+address+" to "+temp);
myMaxCube.setTemperature(address, temp);
});
});
myMaxCube.once('metadataUpdate', function (metadata) {
console.log(metadata);
});
myMaxCube.on('configurationUpdate', function (configuration) {
console.log(configuration);
});
myMaxCube.on('statusUpdate', function (devicesStatus) {
console.log(devicesStatus);
client.publish('maxcube-status', JSON.stringify(devicesStatus));
});