@mschaeffler/node-red-bthome 0.3.0 → 0.4.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/README.md CHANGED
@@ -83,6 +83,7 @@ There are two output ports:
83
83
  |config | type | description |
84
84
  |:------------|:-------|:----------------------------------|
85
85
  |Devices | JSON | configuration of the BT-Home devices |
86
+ |counter is time|Boolean| the counter in encrypted messages is checked again the actual time |
86
87
  |Status-Prefix| string | prefix for the topic for state output |
87
88
  |Event-Prefix | string | prefix for the topic for event output |
88
89
  |Context-Variable| string | name of the variable in flow context storage |
@@ -124,7 +125,7 @@ Example:
124
125
  "encrypted": false,
125
126
  "battery": 100,
126
127
  "gw": { "Shelly Gateway": { "time": 1745395033113, "rssi":-85 } },
127
- data": { "humidity":56, "temperature":-21.3 }
128
+ "data": { "humidity":56, "temperature":-21.3 }
128
129
  }
129
130
  }
130
131
  ```
package/bthome.html CHANGED
@@ -167,6 +167,8 @@
167
167
  <dl class="message-properties">
168
168
  <dt>Devices <span class="property-type">JSON</span></dt>
169
169
  <dd> configuration of the BT-Home devices.</dd>
170
+ <dt>counter is times <span class="property-type">Boolean</span></dt>
171
+ <dd> the counter in encrypted messages is checked again the actual time.</dd>
170
172
  <dt>Status-Prefix <span class="property-type">string</span></dt>
171
173
  <dd> prefix for the topic for state output.</dd>
172
174
  <dt>Event-Prefix <span class="property-type">string</span></dt>
@@ -208,7 +210,7 @@
208
210
  "encrypted": false,<br>
209
211
  "battery": 100,<br>
210
212
  "gw": { "Shelly Gateway": { "time": 1745395033113, "rssi":-85 } },<br>
211
- data": { "humidity":56, "temperature":-21.3 }<br>
213
+ "data": { "humidity":56, "temperature":-21.3 }<br>
212
214
  }
213
215
  }<code>
214
216
 
package/bthome.js CHANGED
@@ -16,6 +16,7 @@ module.exports = function(RED) {
16
16
  this.contextVar = config.contextVar ?? "bthome";
17
17
  this.contextStore = config.contextStore ?? "none";
18
18
  this.data = {};
19
+ this.statistics = { ok:0, err:0, old:0, dup:0 };
19
20
  node.status( "" );
20
21
  if( node.contextStore !== "none" )
21
22
  {
@@ -34,6 +35,7 @@ module.exports = function(RED) {
34
35
  }
35
36
  }
36
37
  } );
38
+ node.flowcontext.set( node.contextVar+"-stat", node.statistics );
37
39
  }
38
40
  for( const mac in node.devices )
39
41
  {
@@ -52,6 +54,7 @@ module.exports = function(RED) {
52
54
  node.on('input', function(msg,send,done) {
53
55
  if( ! Array.isArray( msg.payload.data ) )
54
56
  {
57
+ node.statistics.err++;
55
58
  done( "msg.payload.data must be an Array!" );
56
59
  return;
57
60
  }
@@ -84,8 +87,8 @@ module.exports = function(RED) {
84
87
  if( node.counterTime )
85
88
  {
86
89
  const counterInt = counter[0] | (counter[1]<<8) | (counter[2]<<16) | (counter[3]<<24);
87
- const delta = msgTime - counterInt*1000;
88
- if( delta < -5000 || delta > 15000 )
90
+ const delta = Math.abs( msgTime - counterInt*1000 );
91
+ if( delta > 15000 )
89
92
  {
90
93
  throw new Error( "bthome "+msg.payload.gateway+" "+name+" "+(new Date(counterInt*1000))+" "+delta );
91
94
  }
@@ -172,6 +175,7 @@ module.exports = function(RED) {
172
175
  if( pid < item.pid && pid > 10 /*&& pid > item.pid - 10*/ )
173
176
  {
174
177
  // veraltete Nachricht und nicht reboot
178
+ node.statistics.old++;
175
179
  node.warn( `old ble message ${name} from ${msg.payload.gateway} dropped, ${pid} < ${item.pid}` );
176
180
  return false;
177
181
  }
@@ -182,7 +186,16 @@ module.exports = function(RED) {
182
186
  rssi: msg.payload.rssi ?? null
183
187
  };
184
188
  }
185
- return pid !== null && pid !== item.pid;
189
+ if( pid !== null && pid !== item.pid )
190
+ {
191
+ node.statistics.ok++;
192
+ return true;
193
+ }
194
+ else
195
+ {
196
+ node.statistics.dup++;
197
+ return false;
198
+ }
186
199
  }
187
200
 
188
201
  function newMessage()
@@ -232,6 +245,7 @@ module.exports = function(RED) {
232
245
  }
233
246
  catch( e )
234
247
  {
248
+ node.statistics.err++;
235
249
  done( e.message );
236
250
  }
237
251
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-bthome",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "A Node Red node to decrypt and decode BT-Home frames",
5
5
  "author": {
6
6
  "name": "Mathias Schäffler",