This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
xbee.js
65 lines (52 loc) · 1.51 KB
/
xbee.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
const rx = require("rx");
const xbeeRx = require("xbee-rx");
const R = require("ramda");
const xbee_api = require("xbee-api");
const destinationId = '0013A20040B51A26';
const data = 'TIESTO';
module.exports = xbee = xbeeRx({
serialport: "/dev/ttyUSB4",
serialportOptions: {
baudrate: 57600
},
module: "ZigBee",
api_mode: 2,
debug: false
});
console.log("Monitoring incoming packets (press CTRL-C to stop)");
var stdin = process.stdin;
stdin.setRawMode(true);
/**
* define the sequence of data that is a Ctrl+C
* we use this later to determine when to stop listening
* to the serial port
*/
module.exports.ctrlCStream = rx.Observable.fromEvent(stdin, "data")
.where(function monitorCtrlCOnData(data) {
return data.length === 1 && data[0] === 0x03; // Ctrl+C
})
.take(1);
/**
* configure a stream for handling HELLOs from controlpoints
* the HELLO packet type is within type 144 (0x90) ZIGBEE_RECEIVE_PACKET
*/
module.exports.helloStream = xbee
.monitorTransmissions()
.where(R.propEq("type", 144)) // ZIGBEE_RECEIVE_PACKET
.pluck("data")
.map(function (buffer) {
var s = buffer.toString();
return (s === "\r") ? "\n" : s;
})
.where(R.is(String))
.where(R.equals('DCXHI'));
module.exports.errorCb = function (error) {
console.log("Error during monitoring:\n", error);
xbee.close();
process.exit();
}
module.exports.exitCb = function () {
console.log("\nGot CTRL-C; exiting.");
xbee.close();
process.exit();
}