@mschaeffler/node-red-bthome 0.3.1 → 0.4.1
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 +5 -0
- package/bthome.html +22 -19
- package/bthome.js +15 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -130,6 +130,11 @@ Example:
|
|
|
130
130
|
}
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
If content storage is active, statistical data is also stored in a variable with the suffix `-stat`:
|
|
134
|
+
```
|
|
135
|
+
{ ok:0, err:0, old:0, dup:0 }
|
|
136
|
+
```
|
|
137
|
+
|
|
133
138
|
## Example Flow
|
|
134
139
|
|
|
135
140
|
[example flow](https://github.com/m-schaeffler/node-red-my-nodes/raw/main/node-red-bthome/examples/bthome.json)
|
package/bthome.html
CHANGED
|
@@ -181,17 +181,17 @@
|
|
|
181
181
|
|
|
182
182
|
<h4>Device-Configuration</h4>
|
|
183
183
|
<p>With this JSON string the installed <a href="https://bthome.io">BT-Home</a> devices are configured:</p>
|
|
184
|
-
<code>{
|
|
185
|
-
"<mac address of the device>": { "topic": "<name of the device>", "key": "<encryption key, if device is encrypted>" }
|
|
186
|
-
}</code>
|
|
184
|
+
<pre><code>{
|
|
185
|
+
"<mac address of the device>": { "topic": "<name of the device>", "key": "<encryption key, if device is encrypted>" }
|
|
186
|
+
}</code></pre>
|
|
187
187
|
|
|
188
188
|
<p>An example for such a config from the unit tests:</p>
|
|
189
|
-
<code>{
|
|
190
|
-
"11:22:33:44:55:66": { "topic": "dev_unencrypted_1" }
|
|
191
|
-
"00:01:02:03:04:05": { "topic": "dev_unencrypted_2" }
|
|
192
|
-
"00:10:20:30:40:50": { "topic": "dev_encrypted_1", "key": "00112233445566778899AABBCCDDEEFF" }
|
|
193
|
-
"00:00:00:00:00:00": { "topic": "dev_encrypted_2", "key": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] }
|
|
194
|
-
}</code>
|
|
189
|
+
<pre><code>{
|
|
190
|
+
"11:22:33:44:55:66": { "topic": "dev_unencrypted_1" },
|
|
191
|
+
"00:01:02:03:04:05": { "topic": "dev_unencrypted_2" },
|
|
192
|
+
"00:10:20:30:40:50": { "topic": "dev_encrypted_1", "key": "00112233445566778899AABBCCDDEEFF" },
|
|
193
|
+
"00:00:00:00:00:00": { "topic": "dev_encrypted_2", "key": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] }
|
|
194
|
+
}</code></pre>
|
|
195
195
|
|
|
196
196
|
<h4>Context storage</h4>
|
|
197
197
|
<p>All recorded data can be stored in a flow context variable for</p>
|
|
@@ -202,16 +202,19 @@
|
|
|
202
202
|
</ul>
|
|
203
203
|
|
|
204
204
|
<p>Example:</p>
|
|
205
|
-
<code>{<br>
|
|
206
|
-
"dev_unencrypted_1"
|
|
207
|
-
{
|
|
208
|
-
"pid": 164
|
|
209
|
-
"time": 1745395033113
|
|
210
|
-
"encrypted": false
|
|
211
|
-
"battery": 100
|
|
212
|
-
"gw": { "Shelly Gateway": { "time": 1745395033113, "rssi":-85 } }
|
|
213
|
-
"data": { "humidity":56, "temperature":-21.3 }
|
|
205
|
+
<pre><code>{<br>
|
|
206
|
+
"dev_unencrypted_1":
|
|
207
|
+
{
|
|
208
|
+
"pid": 164,
|
|
209
|
+
"time": 1745395033113,
|
|
210
|
+
"encrypted": false,
|
|
211
|
+
"battery": 100,
|
|
212
|
+
"gw": { "Shelly Gateway": { "time": 1745395033113, "rssi":-85 } },
|
|
213
|
+
"data": { "humidity":56, "temperature":-21.3 }
|
|
214
214
|
}
|
|
215
|
-
}
|
|
215
|
+
}</code></pre>
|
|
216
|
+
|
|
217
|
+
<p>If content storage is active, statistical data is also stored in a variable with the suffix <code>-stat</code>:</p>
|
|
218
|
+
<pre><code>{ ok:0, err:0, old:0, dup:0 }</code></pre>
|
|
216
219
|
|
|
217
220
|
</script>
|
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
|
}
|
|
@@ -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
|
-
|
|
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
|
});
|