@mschaeffler/node-red-bthome 0.5.1 → 1.0.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.
Files changed (3) hide show
  1. package/bthome.html +7 -3
  2. package/bthome.js +24 -12
  3. package/package.json +1 -1
package/bthome.html CHANGED
@@ -5,7 +5,7 @@
5
5
  defaults: {
6
6
  name: {value:""},
7
7
  devices:{value:"[]",required:true},
8
- counterTime:{value:false},
8
+ counterMode:{value:"none",required:true},
9
9
  statusPrefix:{value:""},
10
10
  eventPrefix:{value:""},
11
11
  contextVar:{value:"bthome",required:true},
@@ -67,8 +67,12 @@
67
67
  <input type="text" id="node-input-devices">
68
68
  </div>
69
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;">
70
+ <label for="node-input-counterMode"><i class="fa fa-clock-o"></i> Countermode</label>
71
+ <select type="text" id="node-input-counterMode">
72
+ <option value="none">no check</option>
73
+ <option value="rising">always rising</option>
74
+ <option value="time">time stamp</option>
75
+ </select>
72
76
  </div>
73
77
  <div class="form-row">
74
78
  <label for="node-input-statusPrefix"><i class="fa fa-star"></i> Status-Prefix</label>
package/bthome.js CHANGED
@@ -10,7 +10,7 @@ module.exports = function(RED) {
10
10
  var node = this;
11
11
  this.flowcontext = this.context().flow;
12
12
  this.devices = JSON.parse( config.devices ?? "{}" );
13
- this.counterTime = Boolean( config.counterTime );
13
+ this.counterMode = config.counterMode ?? "none";
14
14
  this.statusPrefix = config.statusPrefix ? config.statusPrefix+'/' : "";
15
15
  this.eventPrefix = config.eventPrefix ? config.eventPrefix +'/' : "";
16
16
  this.contextVar = config.contextVar ?? "bthome";
@@ -84,14 +84,26 @@ module.exports = function(RED) {
84
84
  const mac = Tools.mac2bytes( msg.payload.addr );
85
85
  const ciphertext = Buffer.from( rawdata.slice( 0, -8 ) );
86
86
  const counter = rawdata.slice( -8, -4 );
87
- if( node.counterTime )
87
+ const counterInt = counter[0] | (counter[1]<<8) | (counter[2]<<16) | (counter[3]<<24);
88
+ switch( node.counterMode )
88
89
  {
89
- const counterInt = counter[0] | (counter[1]<<8) | (counter[2]<<16) | (counter[3]<<24);
90
- const delta = msgTime - counterInt*1000;
91
- if( delta > 30000 || delta < -15000 )
92
- {
93
- throw new Error( "bthome "+msg.payload.gateway+" "+name+" "+(new Date(counterInt*1000))+" "+delta );
94
- }
90
+ case "rising":
91
+ if( counterInt > ( item.lastCounter ?? -1 ) )
92
+ {
93
+ item.lastCounter = counterInt;
94
+ }
95
+ else
96
+ {
97
+ throw new Error( "bthome "+msg.payload.gateway+" "+name+" "+counterInt+" <= "+item.lastCounter );
98
+ }
99
+ break;
100
+ case "time":
101
+ const deltaTime = msgTime - counterInt*1000;
102
+ if( deltaTime > 30000 || deltaTime < -15000 )
103
+ {
104
+ throw new Error( "bthome "+msg.payload.gateway+" "+name+" "+(new Date(counterInt*1000))+" "+deltaTime );
105
+ }
106
+ break;
95
107
  }
96
108
  const mic = Buffer.from( rawdata.slice( -4 ) );
97
109
  const nonce = Buffer.from( mac.concat( Tools.uuid16, dib, counter ) );
@@ -238,15 +250,15 @@ module.exports = function(RED) {
238
250
  try
239
251
  {
240
252
  checkMsg();
241
- if( encrypted )
242
- {
243
- decryptMsg();
244
- }
245
253
  if( item == undefined )
246
254
  {
247
255
  item = { pid: null, typeId: null, gw: {} };
248
256
  node.data[name] = item;
249
257
  }
258
+ if( encrypted )
259
+ {
260
+ decryptMsg();
261
+ }
250
262
  decodeMsg();
251
263
  if( checkPid() )
252
264
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-bthome",
3
- "version": "0.5.1",
3
+ "version": "1.0.0",
4
4
  "description": "A Node Red node to decrypt and decode BT-Home frames",
5
5
  "author": {
6
6
  "name": "Mathias Schäffler",