@ncd-io/node-red-enterprise-sensors 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@ncd-io/node-red-enterprise-sensors",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/ncd-io/node-red-enterprise-sensors"
12
+ },
13
+ "keywords": [
14
+ "Wireless",
15
+ "NCD",
16
+ "Sensors",
17
+ "Digi",
18
+ "node-red",
19
+ "enterprise"
20
+ ],
21
+ "author": "Jacob Youngblood",
22
+ "contributors": [
23
+ {
24
+ "name": "Trey Felton"
25
+ },
26
+ {
27
+ "name": "Anil Bhaskar"
28
+ },
29
+ {
30
+ "name": "Travis Elliott"
31
+ }
32
+ ],
33
+ "license": "MIT",
34
+ "node-red": {
35
+ "version": ">=2.0.0",
36
+ "nodes": {
37
+ "ncd-wireless": "wireless.js"
38
+ }
39
+ },
40
+ "dependencies": {
41
+ "ncd-red-comm": "2.0.0"
42
+ }
43
+ }
package/test.js ADDED
@@ -0,0 +1,122 @@
1
+ const NCD = require('./index.js');
2
+ const comm = require('ncd-red-comm');
3
+
4
+ const Queue = require('promise-queue');
5
+
6
+ var serial = new comm.NcdSerial('/dev/tty.usbserial-AL00EXTB', 115200);
7
+ var modem = new NCD.Modem(serial);
8
+
9
+ var gateway = new NCD.Gateway(modem);
10
+
11
+ // modem.send.at_command('ID').then((res) => {
12
+ // console.log('Network ID: '+res.data.map((v) => v.toString(16)).join(''))
13
+ // modem.send.at_command('HP').then((res) => {
14
+ // console.log(res);
15
+ // //console.log('Network ID: '+res.data.map((v) => v.toString(16)).join(''));
16
+ // });
17
+ // });
18
+
19
+ function toHex(n){return ('00' + n.toString(16)).substr(-2);}
20
+
21
+ function toMac(arr){
22
+ return arr.reduce((h,c,i) => {return (i==1?toHex(h):h)+':'+toHex(c);});
23
+ }
24
+ function mac2bytes(mac){
25
+ return mac.split(':').map((v) => parseInt(v, 16));
26
+ }
27
+
28
+ //gateway.control_send("00:00:00:00:00:00:FF:FF", [247, 4, 2]).then(console.log).catch(console.log);
29
+
30
+ //gateway.control_send("00:00:00:00:00:00:FF:FF", [247, 0, ...mac2bytes("00:00:00:00:00:00:FF:FF")]).then(console.log).catch(console.log);
31
+ //gateway.control_send("00:00:00:00:00:00:FF:FF", [248, 0]).then(console.log).catch(console.log);
32
+
33
+ gateway.control_send("00:00:00:00:00:00:FF:FF", [247, 1, 0x7F, 0xFF]).then(console.log).catch(console.log);
34
+ //modem.send.at_command("ID", [0x7BCD >> 8, 0x7BCD & 255]).then(console.log).catch(console.log);
35
+ // gateway.control_send("00:00:00:00:00:00:FF:FF", [248, 0]).then(console.log).catch(console.log);
36
+ // modem.send.at_command('WR').then((res) => {
37
+ // console.log(res);
38
+ // //var SH = res;
39
+ // // modem.send.at_command('SL').then((res) => {
40
+ // // var
41
+ // // })
42
+ // });
43
+
44
+
45
+ gateway.on('sensor_data', (d) => {
46
+ console.log(d);
47
+ });
48
+ // var type;
49
+ // if(typeof gateway.sensor_types[d.sensor_type] == 'undefined'){
50
+ // type = 'unknown';
51
+ // console.log(d);
52
+ // }
53
+ // else type = gateway.sensor_types[d.sensor_type].name;
54
+ // console.log('Incoming data -------------------');
55
+ // console.log('Type: '+type);
56
+ // console.log('Address: '+d.addr);
57
+ // console.log('Readings: ');
58
+ // for(var i in d.sensor_data) console.log(` ${i}: ${d.sensor_data[i]}`);
59
+ // console.log('---------------------------------')
60
+ // });
61
+ // var config_queue = new Queue(1);
62
+ // gateway.on('sensor_mode', (sensor) => {
63
+ // var mac = sensor.mac;
64
+ // console.log(sensor);
65
+ // if(sensor.mode == 'PGM'){
66
+ // config_queue.add(() => {
67
+ // return new Promise((fulfill) => {
68
+ // setTimeout(fulfill, 1000);
69
+ // });
70
+ // });
71
+ // config_queue.add(() => {
72
+ // return new Promise((fulfill, reject) => {
73
+ // console.log('Getting Destination:');
74
+ // gateway.config_get_destination(mac).then((res) => {
75
+ // console.log(res);
76
+ // }).catch((err) => {
77
+ // console.log(err);
78
+ // }).then(fulfill);
79
+ // });
80
+ // });
81
+ // config_queue.add(() => {
82
+ // return new Promise((fulfill, reject) => {
83
+ // console.log('Getting Delay:');
84
+ // gateway.config_get_delay(mac).then((res) => {
85
+ // console.log(res);
86
+ // }).catch((err) => {
87
+ // console.log(err);
88
+ // }).then(fulfill);
89
+ // });
90
+ // });
91
+ // config_queue.add(() => {
92
+ // return new Promise((fulfill, reject) => {
93
+ // console.log('Getting Power:');
94
+ // gateway.config_get_power(mac).then((res) => {
95
+ // console.log(res);
96
+ // }).catch((err) => {
97
+ // console.log(err);
98
+ // }).then(fulfill);
99
+ // });
100
+ // });
101
+ // config_queue.add(() => {
102
+ // return new Promise((fulfill, reject) => {
103
+ // console.log('Getting Retries:');
104
+ // gateway.config_get_retries(mac).then((res) => {
105
+ // console.log(res);
106
+ // }).catch((err) => {
107
+ // console.log(err);
108
+ // }).then(fulfill);
109
+ // });
110
+ // });
111
+ // config_queue.add(() => {
112
+ // return new Promise((fulfill, reject) => {
113
+ // console.log('Getting Network ID:');
114
+ // gateway.config_get_pan_id(mac).then((res) => {
115
+ // console.log(res);
116
+ // }).catch((err) => {
117
+ // console.log(err);
118
+ // }).then(fulfill);
119
+ // });
120
+ // });
121
+ // }
122
+ // });