forked from leachj/mqtt-rfxcom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmqtt-rfxcom.js
32 lines (24 loc) · 910 Bytes
/
mqtt-rfxcom.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
var rfxcom = require('rfxcom');
var mqtt = require('mqtt')
mqttClient = mqtt.createClient(1883, 'localhost');
var rfxtrx = new rfxcom.RfxCom("/dev/tty.usbserial-A1XH8LAT", {debug: false}),
lightwaverf = new rfxcom.Lighting5(rfxtrx, rfxcom.lighting5.LIGHTWAVERF);
mqttClient.on('connect', function () {
mqttClient.subscribe('rfxcom-control');
mqttClient.on('message', function (topic, message) {
console.log(message.toString());
parts = message.toString().split(" ")
if(parts[2] == "on"){
lightwaverf.switchOn(parts[0]+"/"+parts[1]);
} else {
lightwaverf.switchOff(parts[0]+"/"+parts[1]);
}
});
});
rfxtrx.initialise(function () {
console.log("Device initialised");
rfxtrx.on("lighting5", function (evt) {
console.log(evt);
mqttClient.publish('rfxcom-event', evt.id + " " + evt.unitcode + " " + evt.command);
});
});