-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzwave.js
65 lines (53 loc) · 2.08 KB
/
zwave.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
54
55
56
57
58
59
60
61
62
63
64
65
// Z-WAVE SERVER
// =============================================================================
var ZWave = require('openzwave-shared');
// Z-Wave Instance - No Console Output
var zwave = new ZWave({
ConsoleOutput: false,
Logging: false
});
var os = require('os');
// Connection using USB
zwave.connect('/dev/cu.usbmodem1411');
zwavedriverpaths = {
"darwin" : '/dev/cu.usbmodem1411',
"linux" : '/dev/ttyACM0'
}
zwave.connect( zwavedriverpaths[os.platform()] );
var scanComplete = false;
// // =============================================================//
// // FOR TESTING //
// // =============================================================//
// zwave.on('notification', function(nodeid, notif) { //
// console.log('====> Notification, hit ^C to finish.'); //
// console.log('nodeid: ' + nodeid + ', notif: ' + notif); //
// }); //
// //
// zwave.on('controller command', function(r,s) { //
// console.log('controller commmand feedback: r=%d, s=%d',r,s); //
// }); //
// //
// //==============================================================//
// Make sure the initial scan is complete. Ignore everything until then
zwave.on('scan complete', function() {
scanComplete = true;
});
// Check for changing values and update the database
zwave.on('value changed', function(node, comclass, value) {
if(scanComplete) {
var nodeid = value.node_id;
var value = value.value;
var Node = require('./database/nodes.schema');
Node.findOneAndUpdate({ node_id: nodeid }, { value: value }, function(err, node) {
if (err) throw err;
});
}
});
// Exit Process
process.on('SIGINT', function() {
console.log('Z-Wave disconnecting...');
zwave.disconnect('/dev/cu.usbmodem1411');
process.exit();
});
// Exports
module.exports = zwave;