@mschaeffler/node-red-bthome 0.2.1 → 0.2.3

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.
Files changed (3) hide show
  1. package/bthome.html +21 -5
  2. package/bthome.js +6 -0
  3. package/package.json +1 -1
package/bthome.html CHANGED
@@ -5,10 +5,11 @@
5
5
  defaults: {
6
6
  name: {value:""},
7
7
  devices:{value:"[]",required:true},
8
+ counterTime:{value:false},
8
9
  statusPrefix:{value:""},
9
10
  eventPrefix:{value:""},
10
11
  contextVar:{value:"bthome",required:true},
11
- contextStore:{value:"",required:true}
12
+ contextStore:{value:"none",required:true}
12
13
  },
13
14
  inputs:1,
14
15
  outputs:2,
@@ -39,6 +40,17 @@
39
40
  }
40
41
  });
41
42
  const currentStore = node.contextStore || '';
43
+ // set changed handler
44
+ $("#node-input-contextStore").on('change',function() {
45
+ console.log($("#node-input-contextStore").val());
46
+ if( $("#node-input-contextStore").val() == "none" ) {
47
+ $("#node-contextVar-line").hide();
48
+ $("#node-input-contextVar").val("bthome");
49
+ }
50
+ else {
51
+ $("#node-contextVar-line").show();
52
+ }
53
+ });
42
54
  // select the current option
43
55
  $("#node-input-contextStore").val(currentStore);
44
56
  }
@@ -54,6 +66,10 @@
54
66
  <label for="node-input-devices"><i class="fa fa-bluetooth-b"></i> Devices</label>
55
67
  <input type="text" id="node-input-devices">
56
68
  </div>
69
+ <div class="form-row">
70
+ <label for="node-input-counterTime"><i class="fa fa-clock-o"></i> counter is time</label>
71
+ <input type="checkbox" id="node-input-counterTime" style="display:inline-block; width:20px; vertical-align:baseline;">
72
+ </div>
57
73
  <div class="form-row">
58
74
  <label for="node-input-statusPrefix"><i class="fa fa-star"></i> Status-Prefix</label>
59
75
  <input type="text" id="node-input-statusPrefix"></input>
@@ -62,14 +78,14 @@
62
78
  <label for="node-input-eventPrefix"><i class="fa fa-star-o"></i> Event-Prefix</label>
63
79
  <input type="text" id="node-input-eventPrefix"></input>
64
80
  </div>
65
- <div class="form-row">
66
- <label for="node-input-contextVar"><i class="fa fa-database"></i> Context-Variable</label>
67
- <input type="text" id="node-input-contextVar"></input>
68
- </div>
69
81
  <div class="form-row">
70
82
  <label for="node-input-contextStore"><i class="fa fa-database"></i> Contextstore</label>
71
83
  <select type="text" id="node-input-contextStore"></select>
72
84
  </div>
85
+ <div class="form-row" id="node-contextVar-line">
86
+ <label for="node-input-contextVar"><i class="fa fa-database"></i> Context-Variable</label>
87
+ <input type="text" id="node-input-contextVar"></input>
88
+ </div>
73
89
  </script>
74
90
 
75
91
  <script type="text/x-red" data-help-name="bthome">
package/bthome.js CHANGED
@@ -9,6 +9,7 @@ module.exports = function(RED) {
9
9
  var node = this;
10
10
  this.flowcontext = this.context().flow;
11
11
  this.devices = JSON.parse( config.devices ?? "{}" );
12
+ this.counterTime = Boolean( config.counterTime );
12
13
  this.statusPrefix = config.statusPrefix ? config.statusPrefix+'/' : "";
13
14
  this.eventPrefix = config.eventPrefix ? config.eventPrefix +'/' : "";
14
15
  this.contextVar = config.contextVar ?? "bthome";
@@ -98,12 +99,17 @@ module.exports = function(RED) {
98
99
  const uuid16 = [0xD2,0xFC];
99
100
  const ciphertext = Buffer.from( rawdata.slice( 0, -8 ) );
100
101
  const counter = rawdata.slice( -8, -4 );
102
+ const counterInt = counter[0] | (counter[1]<<8) | (counter[2]<<16) | (counter[3]<<24);
101
103
  const mic = Buffer.from( rawdata.slice( -4 ) );
102
104
  const nonce = Buffer.from( mac.concat( uuid16, dib, counter ) );
103
105
  const decipher = Crypto.createDecipheriv( "aes-128-ccm", node.devices[msg.payload.addr].key, nonce, { authTagLength: 4 } );
104
106
  decipher.setAuthTag( mic );
105
107
  rawdata = Array.from( decipher.update( ciphertext ) );
106
108
  decipher.final();
109
+ if( node.counterTime && Date.now() - counterInt*1000 > 7500 )
110
+ {
111
+ node.error("bthome "+name+" "+(new Date(counterInt*1000))+" "+(Date.now()-counterInt*1000));
112
+ }
107
113
  }
108
114
 
109
115
  function setData(name,value)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-bthome",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "A Node Red node to decrypt and decode BT-Home frames",
5
5
  "author": {
6
6
  "name": "Mathias Schäffler",