@mschaeffler/node-red-bthome 0.2.0 → 0.2.2

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
@@ -21,7 +21,7 @@ The raw data frames are captured by Shelly devices with Bluetooth (Gen2 up to Ge
21
21
 
22
22
  ## Encryption
23
23
 
24
- is at the moment not supported, an update will follow shortly.
24
+ This node can decrypt [encrypted messages](https://bthome.io/encryption/), if the AES key is set in the `devices` parameter.
25
25
 
26
26
  ## Install
27
27
 
package/bthome.html CHANGED
@@ -8,7 +8,7 @@
8
8
  statusPrefix:{value:""},
9
9
  eventPrefix:{value:""},
10
10
  contextVar:{value:"bthome",required:true},
11
- contextStore:{value:"",required:true}
11
+ contextStore:{value:"none",required:true}
12
12
  },
13
13
  inputs:1,
14
14
  outputs:2,
@@ -39,6 +39,17 @@
39
39
  }
40
40
  });
41
41
  const currentStore = node.contextStore || '';
42
+ // set changed handler
43
+ $("#node-input-contextStore").on('change',function() {
44
+ console.log($("#node-input-contextStore").val());
45
+ if( $("#node-input-contextStore").val() == "none" ) {
46
+ $("#node-contextVar-line").hide();
47
+ $("#node-input-contextVar").val("bthome");
48
+ }
49
+ else {
50
+ $("#node-contextVar-line").show();
51
+ }
52
+ });
42
53
  // select the current option
43
54
  $("#node-input-contextStore").val(currentStore);
44
55
  }
@@ -62,14 +73,14 @@
62
73
  <label for="node-input-eventPrefix"><i class="fa fa-star-o"></i> Event-Prefix</label>
63
74
  <input type="text" id="node-input-eventPrefix"></input>
64
75
  </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
76
  <div class="form-row">
70
77
  <label for="node-input-contextStore"><i class="fa fa-database"></i> Contextstore</label>
71
78
  <select type="text" id="node-input-contextStore"></select>
72
79
  </div>
80
+ <div class="form-row" id="node-contextVar-line">
81
+ <label for="node-input-contextVar"><i class="fa fa-database"></i> Context-Variable</label>
82
+ <input type="text" id="node-input-contextVar"></input>
83
+ </div>
73
84
  </script>
74
85
 
75
86
  <script type="text/x-red" data-help-name="bthome">
@@ -92,7 +103,7 @@
92
103
  <a href="https://raw.githubusercontent.com/m-schaeffler/ShellyScripts/refs/heads/main/ShellyBlu.js">This is the script to be used.</a>
93
104
 
94
105
  <h3>Encryption</h3>
95
- <p>is at the moment not supported, an update will follow shortly.</p>
106
+ <p>This node can decrypt <a href="https://bthome.io/encryption/">encrypted messages</a>, if the AES key is set in the <code>devices</code> parameter.</p>
96
107
 
97
108
  <h3>Input</h3>
98
109
  <dl class="message-properties">
package/bthome.js CHANGED
@@ -98,12 +98,18 @@ module.exports = function(RED) {
98
98
  const uuid16 = [0xD2,0xFC];
99
99
  const ciphertext = Buffer.from( rawdata.slice( 0, -8 ) );
100
100
  const counter = rawdata.slice( -8, -4 );
101
+ const counterInt = counter[0] | (counter[1]<<8) | (counter[2]<<16) | (counter[3]<<24);
101
102
  const mic = Buffer.from( rawdata.slice( -4 ) );
102
103
  const nonce = Buffer.from( mac.concat( uuid16, dib, counter ) );
103
104
  const decipher = Crypto.createDecipheriv( "aes-128-ccm", node.devices[msg.payload.addr].key, nonce, { authTagLength: 4 } );
104
105
  decipher.setAuthTag( mic );
105
106
  rawdata = Array.from( decipher.update( ciphertext ) );
106
107
  decipher.final();
108
+
109
+ if( 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.0",
3
+ "version": "0.2.2",
4
4
  "description": "A Node Red node to decrypt and decode BT-Home frames",
5
5
  "author": {
6
6
  "name": "Mathias Schäffler",