@mschaeffler/node-red-bthome 0.4.1 → 0.5.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 (2) hide show
  1. package/bthome.js +18 -5
  2. package/package.json +1 -1
package/bthome.js CHANGED
@@ -3,6 +3,13 @@ const Tools = require( './tools.js' );
3
3
  const Rawdata = require( "./rawdata.js" );
4
4
  const BtEvent = require( "./btevent.js" );
5
5
 
6
+ /*
7
+ const state2str = {
8
+ "514": ["close","open"],
9
+ "undefined": ["","near","middle","far"]
10
+ };
11
+ */
12
+
6
13
  module.exports = function(RED) {
7
14
 
8
15
  function BtHomeNode(config) {
@@ -16,7 +23,7 @@ module.exports = function(RED) {
16
23
  this.contextVar = config.contextVar ?? "bthome";
17
24
  this.contextStore = config.contextStore ?? "none";
18
25
  this.data = {};
19
- this.statistics = { ok:0, err:0, old:0, dup:0 };
26
+ this.statistics = { ok:0, dup:0, old:0, err:0 };
20
27
  node.status( "" );
21
28
  if( node.contextStore !== "none" )
22
29
  {
@@ -87,8 +94,8 @@ module.exports = function(RED) {
87
94
  if( node.counterTime )
88
95
  {
89
96
  const counterInt = counter[0] | (counter[1]<<8) | (counter[2]<<16) | (counter[3]<<24);
90
- const delta = Math.abs( msgTime - counterInt*1000 );
91
- if( delta > 15000 )
97
+ const delta = msgTime - counterInt*1000;
98
+ if( delta > 30000 || delta < -15000 )
92
99
  {
93
100
  throw new Error( "bthome "+msg.payload.gateway+" "+name+" "+(new Date(counterInt*1000))+" "+delta );
94
101
  }
@@ -130,8 +137,11 @@ module.exports = function(RED) {
130
137
  case 0x21:
131
138
  events.pushEvent( "motion", rawdata.getEnum( ["","motion"] ) );
132
139
  break;
140
+ case 0x2C:
141
+ setData( "vibration", Boolean( rawdata.getUInt8() ) );
142
+ break;
133
143
  case 0x2D:
134
- setData( "state", rawdata.getEnum( ["close","open"] ) );
144
+ setData( "state", rawdata.getUInt8() );
135
145
  break;
136
146
  case 0x2E:
137
147
  setData( "humidity", rawdata.getUInt8() );
@@ -142,6 +152,9 @@ module.exports = function(RED) {
142
152
  case 0x3F:
143
153
  setData( "tilt", rawdata.getInt16() * 0.1 );
144
154
  break;
155
+ case 0x40:
156
+ setData( "distance", rawdata.getUInt16() );
157
+ break;
145
158
  case 0x45:
146
159
  setData( "temperature", rawdata.getInt16() * 0.1 );
147
160
  break;
@@ -233,7 +246,7 @@ module.exports = function(RED) {
233
246
  }
234
247
  if( item == undefined )
235
248
  {
236
- item = { pid: null, gw: {} };
249
+ item = { pid: null, typeId: null, gw: {} };
237
250
  node.data[name] = item;
238
251
  }
239
252
  decodeMsg();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-bthome",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "A Node Red node to decrypt and decode BT-Home frames",
5
5
  "author": {
6
6
  "name": "Mathias Schäffler",