@mschaeffler/node-red-bthome 0.5.0 → 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.
- package/bthome.html +7 -3
- package/bthome.js +30 -20
- 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
|
-
|
|
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-
|
|
71
|
-
<
|
|
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
|
@@ -3,13 +3,6 @@ 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
|
-
|
|
13
6
|
module.exports = function(RED) {
|
|
14
7
|
|
|
15
8
|
function BtHomeNode(config) {
|
|
@@ -17,7 +10,7 @@ module.exports = function(RED) {
|
|
|
17
10
|
var node = this;
|
|
18
11
|
this.flowcontext = this.context().flow;
|
|
19
12
|
this.devices = JSON.parse( config.devices ?? "{}" );
|
|
20
|
-
this.
|
|
13
|
+
this.counterMode = config.counterMode ?? "none";
|
|
21
14
|
this.statusPrefix = config.statusPrefix ? config.statusPrefix+'/' : "";
|
|
22
15
|
this.eventPrefix = config.eventPrefix ? config.eventPrefix +'/' : "";
|
|
23
16
|
this.contextVar = config.contextVar ?? "bthome";
|
|
@@ -91,14 +84,26 @@ module.exports = function(RED) {
|
|
|
91
84
|
const mac = Tools.mac2bytes( msg.payload.addr );
|
|
92
85
|
const ciphertext = Buffer.from( rawdata.slice( 0, -8 ) );
|
|
93
86
|
const counter = rawdata.slice( -8, -4 );
|
|
94
|
-
|
|
87
|
+
const counterInt = counter[0] | (counter[1]<<8) | (counter[2]<<16) | (counter[3]<<24);
|
|
88
|
+
switch( node.counterMode )
|
|
95
89
|
{
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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;
|
|
102
107
|
}
|
|
103
108
|
const mic = Buffer.from( rawdata.slice( -4 ) );
|
|
104
109
|
const nonce = Buffer.from( mac.concat( Tools.uuid16, dib, counter ) );
|
|
@@ -141,7 +146,12 @@ module.exports = function(RED) {
|
|
|
141
146
|
setData( "vibration", Boolean( rawdata.getUInt8() ) );
|
|
142
147
|
break;
|
|
143
148
|
case 0x2D:
|
|
144
|
-
|
|
149
|
+
let state = rawdata.getUInt8();
|
|
150
|
+
if( item.typeId === 0x0202 )
|
|
151
|
+
{
|
|
152
|
+
state = Boolean( state );
|
|
153
|
+
}
|
|
154
|
+
setData( "state", state );
|
|
145
155
|
break;
|
|
146
156
|
case 0x2E:
|
|
147
157
|
setData( "humidity", rawdata.getUInt8() );
|
|
@@ -240,15 +250,15 @@ module.exports = function(RED) {
|
|
|
240
250
|
try
|
|
241
251
|
{
|
|
242
252
|
checkMsg();
|
|
243
|
-
if( encrypted )
|
|
244
|
-
{
|
|
245
|
-
decryptMsg();
|
|
246
|
-
}
|
|
247
253
|
if( item == undefined )
|
|
248
254
|
{
|
|
249
255
|
item = { pid: null, typeId: null, gw: {} };
|
|
250
256
|
node.data[name] = item;
|
|
251
257
|
}
|
|
258
|
+
if( encrypted )
|
|
259
|
+
{
|
|
260
|
+
decryptMsg();
|
|
261
|
+
}
|
|
252
262
|
decodeMsg();
|
|
253
263
|
if( checkPid() )
|
|
254
264
|
{
|