@mschaeffler/node-red-logic 0.0.6 → 0.0.7
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 +35 -1
- package/counter.js +5 -7
- package/logic_and.html +4 -2
- package/logic_and.js +22 -19
- package/logic_bool.js +9 -2
- package/logic_or.html +4 -2
- package/logic_or.js +22 -19
- package/{math_plus.html → math_number.html} +8 -12
- package/math_number.js +26 -0
- package/math_reduce.html +94 -0
- package/math_reduce.js +86 -0
- package/package.json +4 -3
- package/math_plus.js +0 -41
package/README.md
CHANGED
|
@@ -12,7 +12,41 @@ $ npm install @mschaeffler/node-red-logic
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
### bool
|
|
16
|
+
|
|
17
|
+
Converts payload to a bool value:
|
|
18
|
+
|type|value|is converted to|
|
|
19
|
+
|:---|:----|:--------------|
|
|
20
|
+
|bool|false|false|
|
|
21
|
+
||true|true|
|
|
22
|
+
|number|0|false|
|
|
23
|
+
||1|true|
|
|
24
|
+
|string|false|false|
|
|
25
|
+
||0|false|
|
|
26
|
+
||off|false|
|
|
27
|
+
||true|true|
|
|
28
|
+
||1|true|
|
|
29
|
+
||on|true|
|
|
30
|
+
|
|
31
|
+
#### Input
|
|
32
|
+
|
|
33
|
+
The message property to be used as payload can be defined with the `Property` property.
|
|
34
|
+
|
|
35
|
+
|msg. | type | description |
|
|
36
|
+
|:-------|:-------|:----------------------------------|
|
|
37
|
+
|payload | | input value. |
|
|
38
|
+
|
|
39
|
+
#### Output
|
|
40
|
+
|
|
41
|
+
|msg. | type | description |
|
|
42
|
+
|:-------|:-------|:----------------------------------|
|
|
43
|
+
|payload | boolean | bool value of payload.|
|
|
44
|
+
|
|
45
|
+
#### Parameters
|
|
46
|
+
|
|
47
|
+
|config| type | description |
|
|
48
|
+
|:-----|:-------|:----------------------------------|
|
|
49
|
+
|Property| string | defines the message property to be used as payload.|
|
|
16
50
|
|
|
17
51
|
### or
|
|
18
52
|
|
package/counter.js
CHANGED
|
@@ -7,20 +7,18 @@ module.exports = function(RED) {
|
|
|
7
7
|
var context = this.context();
|
|
8
8
|
|
|
9
9
|
node.on('input', function(msg,send,done) {
|
|
10
|
-
|
|
10
|
+
msg.count = context.get( "count" ) ?? 0;
|
|
11
11
|
if( msg.reset || msg.topic==="init" )
|
|
12
12
|
{
|
|
13
|
-
|
|
13
|
+
msg.count = 0;
|
|
14
14
|
}
|
|
15
15
|
else
|
|
16
16
|
{
|
|
17
|
-
|
|
17
|
+
msg.count++;
|
|
18
18
|
}
|
|
19
|
-
context.set( "
|
|
19
|
+
context.set( "count", msg.count );
|
|
20
20
|
|
|
21
|
-
msg.count
|
|
22
|
-
|
|
23
|
-
node.status( data );
|
|
21
|
+
node.status( msg.count );
|
|
24
22
|
send( msg );
|
|
25
23
|
done();
|
|
26
24
|
});
|
package/logic_and.html
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
color: "#C0DEED",
|
|
5
5
|
defaults: {
|
|
6
6
|
name:{value:""},
|
|
7
|
-
property:{value:"payload",required:true},
|
|
8
|
-
minData:{value:"1",validate:
|
|
7
|
+
property:{value:"payload", required:true},
|
|
8
|
+
minData:{value:"1", required:true, validate:function(v){
|
|
9
|
+
return v!=='' && !isNaN(v) && Number(v)>0;
|
|
10
|
+
}}
|
|
9
11
|
},
|
|
10
12
|
inputs:1,
|
|
11
13
|
outputs:1,
|
package/logic_and.js
CHANGED
|
@@ -12,29 +12,32 @@ module.exports = function(RED) {
|
|
|
12
12
|
node.on('input', function(msg,send,done) {
|
|
13
13
|
const payload = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
data[msg.topic] = payload;
|
|
17
|
-
context.set( "data", data );
|
|
18
|
-
|
|
19
|
-
msg.payload = true;
|
|
20
|
-
let count = 0;
|
|
21
|
-
for( const item in data )
|
|
15
|
+
if( payload !=== null )
|
|
22
16
|
{
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
let data = context.get( "data" ) ?? {};
|
|
18
|
+
data[msg.topic] = payload;
|
|
19
|
+
context.set( "data", data );
|
|
20
|
+
|
|
21
|
+
msg.payload = true;
|
|
22
|
+
msg.count = 0;
|
|
23
|
+
for( const item in data )
|
|
25
24
|
{
|
|
26
|
-
msg.
|
|
25
|
+
msg.count++;
|
|
26
|
+
if( ! data[item] )
|
|
27
|
+
{
|
|
28
|
+
msg.payload = false;
|
|
29
|
+
}
|
|
27
30
|
}
|
|
28
|
-
}
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
if( msg.count >= node.minData )
|
|
33
|
+
{
|
|
34
|
+
node.status( msg.payload );
|
|
35
|
+
send( msg );
|
|
36
|
+
}
|
|
37
|
+
else
|
|
38
|
+
{
|
|
39
|
+
node.status( "waiting for data" );
|
|
40
|
+
}
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
done();
|
package/logic_bool.js
CHANGED
|
@@ -10,8 +10,15 @@ module.exports = function(RED) {
|
|
|
10
10
|
node.on('input', function(msg,send,done) {
|
|
11
11
|
msg.payload = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
if( msg.payload !== null )
|
|
14
|
+
{
|
|
15
|
+
node.status( msg.payload );
|
|
16
|
+
send( msg );
|
|
17
|
+
}
|
|
18
|
+
else
|
|
19
|
+
{
|
|
20
|
+
node.status( "error" );
|
|
21
|
+
}
|
|
15
22
|
done();
|
|
16
23
|
});
|
|
17
24
|
}
|
package/logic_or.html
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
color: "#C0DEED",
|
|
5
5
|
defaults: {
|
|
6
6
|
name:{value:""},
|
|
7
|
-
property:{value:"payload",required:true},
|
|
8
|
-
minData:{value:"1",validate:
|
|
7
|
+
property:{value:"payload", required:true},
|
|
8
|
+
minData:{value:"1", required:true, validate:function(v){
|
|
9
|
+
return v!=='' && !isNaN(v) && Number(v)>0;
|
|
10
|
+
}}
|
|
9
11
|
},
|
|
10
12
|
inputs:1,
|
|
11
13
|
outputs:1,
|
package/logic_or.js
CHANGED
|
@@ -12,29 +12,32 @@ module.exports = function(RED) {
|
|
|
12
12
|
node.on('input', function(msg,send,done) {
|
|
13
13
|
const payload = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
data[msg.topic] = payload;
|
|
17
|
-
context.set( "data", data );
|
|
18
|
-
|
|
19
|
-
msg.payload = false;
|
|
20
|
-
let count = 0;
|
|
21
|
-
for( const item in data )
|
|
15
|
+
if( payload !== null )
|
|
22
16
|
{
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
let data = context.get( "data" ) ?? {};
|
|
18
|
+
data[msg.topic] = payload;
|
|
19
|
+
context.set( "data", data );
|
|
20
|
+
|
|
21
|
+
msg.payload = false;
|
|
22
|
+
msg.count = 0;
|
|
23
|
+
for( const item in data )
|
|
25
24
|
{
|
|
26
|
-
msg.
|
|
25
|
+
msg.count++;
|
|
26
|
+
if( data[item] )
|
|
27
|
+
{
|
|
28
|
+
msg.payload = true;
|
|
29
|
+
}
|
|
27
30
|
}
|
|
28
|
-
}
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
if( msg.count >= node.minData )
|
|
33
|
+
{
|
|
34
|
+
node.status( msg.payload );
|
|
35
|
+
send( msg );
|
|
36
|
+
}
|
|
37
|
+
else
|
|
38
|
+
{
|
|
39
|
+
node.status( "waiting for data" );
|
|
40
|
+
}
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
done();
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('
|
|
2
|
+
RED.nodes.registerType('tonumber',{
|
|
3
3
|
category: 'function',
|
|
4
4
|
color: "#C0DEED",
|
|
5
5
|
defaults: {
|
|
6
6
|
name:{value:""},
|
|
7
|
-
property:{value:"payload",required:true}
|
|
8
|
-
minData:{value:"1",validate:RED.validators.number(),required:true}
|
|
7
|
+
property:{value:"payload",required:true}
|
|
9
8
|
},
|
|
10
9
|
inputs:1,
|
|
11
10
|
outputs:1,
|
|
12
|
-
icon: "font-awesome/fa-
|
|
11
|
+
icon: "font-awesome/fa-adjust",
|
|
13
12
|
label: function() {
|
|
14
|
-
return this.name||"
|
|
13
|
+
return this.name||"to number";
|
|
15
14
|
},
|
|
15
|
+
paletteLabel: "to number",
|
|
16
16
|
inputLabels: 'input',
|
|
17
|
-
outputLabels: '
|
|
17
|
+
outputLabels: 'number',
|
|
18
18
|
oneditprepare: function() {
|
|
19
19
|
$("#node-input-property").typedInput({
|
|
20
20
|
type:"msg",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
});
|
|
26
26
|
</script>
|
|
27
27
|
|
|
28
|
-
<script type="text/html" data-template-name="
|
|
28
|
+
<script type="text/html" data-template-name="tonumber">
|
|
29
29
|
<div class="form-row">
|
|
30
30
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
31
31
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
@@ -35,13 +35,9 @@
|
|
|
35
35
|
<input type="text" id="node-input-property">
|
|
36
36
|
<input type="hidden" id="node-input-property-type">
|
|
37
37
|
</div>
|
|
38
|
-
<div class="form-row">
|
|
39
|
-
<label for="node-input-minData"><i class="fa fa-tag"></i> min. Data</label>
|
|
40
|
-
<input type="text" id="node-input-minData">
|
|
41
|
-
</div>
|
|
42
38
|
</script>
|
|
43
39
|
|
|
44
|
-
<script type="text/html" data-help-name="
|
|
40
|
+
<script type="text/html" data-help-name="tonumber">
|
|
45
41
|
|
|
46
42
|
<p>.</p>
|
|
47
43
|
|
package/math_number.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module.exports = function(RED) {
|
|
2
|
+
|
|
3
|
+
function NumberNode(config) {
|
|
4
|
+
RED.nodes.createNode(this,config);
|
|
5
|
+
//this.config = config;
|
|
6
|
+
var node = this;
|
|
7
|
+
this.property = config.property || "payload";
|
|
8
|
+
|
|
9
|
+
node.on('input', function(msg,send,done) {
|
|
10
|
+
msg.payload = Number( RED.util.getMessageProperty( msg, node.property ) );
|
|
11
|
+
|
|
12
|
+
if( ! isNaN( msg.payload ) )
|
|
13
|
+
{
|
|
14
|
+
node.status( msg.payload );
|
|
15
|
+
send( msg );
|
|
16
|
+
}
|
|
17
|
+
else
|
|
18
|
+
{
|
|
19
|
+
node.status( "not a Number" );
|
|
20
|
+
}
|
|
21
|
+
done();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
RED.nodes.registerType("tonumber",NumberNode);
|
|
26
|
+
}
|
package/math_reduce.html
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('reduce',{
|
|
3
|
+
category: 'function',
|
|
4
|
+
color: "#C0DEED",
|
|
5
|
+
defaults: {
|
|
6
|
+
name:{value:""},
|
|
7
|
+
property:{value:"payload", required:true},
|
|
8
|
+
minMean:{value:"1", required:true, validate:function(v){
|
|
9
|
+
return v!=='' && !isNaN(v) && Number(v)>0;}
|
|
10
|
+
},
|
|
11
|
+
maxMean:{value:"1", required:true, validate:function(v){
|
|
12
|
+
const minMean = $("#node-input-minMean").length ? $("#node-input-minMean").val() : this.minMean;
|
|
13
|
+
return v!=='' && !isNaN(v) && Number(v)>=minMean;}
|
|
14
|
+
},
|
|
15
|
+
minData:{value:"1", required:true, validate:function(v){
|
|
16
|
+
return v!=='' && !isNaN(v) && Number(v)>0;}
|
|
17
|
+
},
|
|
18
|
+
algo:{value:"", required:true}
|
|
19
|
+
},
|
|
20
|
+
inputs:1,
|
|
21
|
+
outputs:1,
|
|
22
|
+
icon: function() {
|
|
23
|
+
switch( this.algo )
|
|
24
|
+
{
|
|
25
|
+
case "add": return "font-awesome/fa-plus";
|
|
26
|
+
case "mean": return "font-awesome/fa-indent";
|
|
27
|
+
case "prod": return "font-awesome/fa-asterisk";
|
|
28
|
+
case "min": return "font-awesome/fa-sort-numeric-desc";
|
|
29
|
+
case "max": return "font-awesome/fa-sort-numeric-asc";
|
|
30
|
+
default: return "font-awesome/fa-flask";
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
label: function() {
|
|
34
|
+
return this.name||this.algo||"reduce";
|
|
35
|
+
},
|
|
36
|
+
inputLabels: 'input',
|
|
37
|
+
outputLabels: 'output',
|
|
38
|
+
oneditprepare: function() {
|
|
39
|
+
$("#node-input-property").typedInput({
|
|
40
|
+
type:"msg",
|
|
41
|
+
types:["msg"],
|
|
42
|
+
typeField: "#node-input-property-type"
|
|
43
|
+
});
|
|
44
|
+
$("#node-input-algo").typedInput({
|
|
45
|
+
types:[{
|
|
46
|
+
value:"algo",
|
|
47
|
+
options: [
|
|
48
|
+
{ value: "add", label: "Addition"},
|
|
49
|
+
{ value: "mean", label: "Mean Value"},
|
|
50
|
+
{ value: "prod", label: "Product"},
|
|
51
|
+
{ value: "min", label: "Minimum" },
|
|
52
|
+
{ value: "max", label: "Maximum" }
|
|
53
|
+
]
|
|
54
|
+
}]
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<script type="text/html" data-template-name="reduce">
|
|
61
|
+
<div class="form-row">
|
|
62
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
63
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
64
|
+
</div>
|
|
65
|
+
<div class="form-row">
|
|
66
|
+
<label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
|
|
67
|
+
<input type="text" id="node-input-property">
|
|
68
|
+
<input type="hidden" id="node-input-property-type">
|
|
69
|
+
</div>
|
|
70
|
+
<div class="form-row">
|
|
71
|
+
<label for="node-input-minMean"><i class="fa fa-hourglass-o"></i> min. Mean</label>
|
|
72
|
+
<input type="text" id="node-input-minMean">
|
|
73
|
+
</div>
|
|
74
|
+
<div class="form-row">
|
|
75
|
+
<label for="node-input-maxMean"><i class="fa fa-hourglass"></i> max. Mean</label>
|
|
76
|
+
<input type="text" id="node-input-maxMean">
|
|
77
|
+
</div>
|
|
78
|
+
<div class="form-row">
|
|
79
|
+
<label for="node-input-minData"><i class="fa fa-check-square-o "></i> min. Data</label>
|
|
80
|
+
<input type="text" id="node-input-minData">
|
|
81
|
+
</div>
|
|
82
|
+
<div class="form-row">
|
|
83
|
+
<label for="node-input-algo"><i class="fa fa-flask"></i> Algorithm</label>
|
|
84
|
+
<input type="text" id="node-input-algo">
|
|
85
|
+
</div>
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<script type="text/html" data-help-name="reduce">
|
|
89
|
+
|
|
90
|
+
<p>.</p>
|
|
91
|
+
|
|
92
|
+
<h3>Input</h3>
|
|
93
|
+
|
|
94
|
+
</script>
|
package/math_reduce.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
module.exports = function(RED) {
|
|
2
|
+
|
|
3
|
+
function ReduceNode(config) {
|
|
4
|
+
RED.nodes.createNode(this,config);
|
|
5
|
+
//this.config = config;
|
|
6
|
+
var node = this;
|
|
7
|
+
var context = this.context();
|
|
8
|
+
this.property = config.property || "payload";
|
|
9
|
+
this.minMean = Number( config.minMean );
|
|
10
|
+
this.maxMean = Number( config.maxMean );
|
|
11
|
+
this.minData = Number( config.minData );
|
|
12
|
+
this.algo = config.algo;
|
|
13
|
+
|
|
14
|
+
node.on('input', function(msg,send,done) {
|
|
15
|
+
if( msg.reset || msg.topic==="init" )
|
|
16
|
+
{
|
|
17
|
+
context.set( "data", {} );
|
|
18
|
+
node.status( "" );
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
{
|
|
22
|
+
const payload = Number( RED.util.getMessageProperty( msg, node.property ) );
|
|
23
|
+
if( ! isNaN( payload ) )
|
|
24
|
+
{
|
|
25
|
+
let data = context.get( "data" ) ?? {};
|
|
26
|
+
let item = data[msg.topic] ?? [];
|
|
27
|
+
item.push( payload )
|
|
28
|
+
data[msg.topic] = item;
|
|
29
|
+
|
|
30
|
+
msg.count = 0;
|
|
31
|
+
switch( node.algo )
|
|
32
|
+
{
|
|
33
|
+
case "add":
|
|
34
|
+
case "mean": msg.payload = 0; break;
|
|
35
|
+
case "prod": msg.payload = 1; break;
|
|
36
|
+
case "min": msg.payload = Number.MAX_SAFE_INTEGER; break;
|
|
37
|
+
case "max": msg.payload = Number.MIN_SAFE_INTEGER; break;
|
|
38
|
+
default: done( "invalid algo: "+node.algo ); return;
|
|
39
|
+
}
|
|
40
|
+
for( const key in data )
|
|
41
|
+
{
|
|
42
|
+
if( data[key].length >= node.minMean )
|
|
43
|
+
{
|
|
44
|
+
msg.count++;
|
|
45
|
+
while( data[key].length > node.maxMean )
|
|
46
|
+
{
|
|
47
|
+
data[key].shift();
|
|
48
|
+
}
|
|
49
|
+
const help = data[key].reduce( (accumulator,value)=>accumulator+value ) / data[key].length;
|
|
50
|
+
switch( node.algo )
|
|
51
|
+
{
|
|
52
|
+
case "add":
|
|
53
|
+
case "mean": msg.payload += help; break;
|
|
54
|
+
case "prod": msg.payload *= help; break;
|
|
55
|
+
case "min": msg.payload = Math.min( msg.payload, help ); break;
|
|
56
|
+
case "max": msg.payload = Math.max( msg.payload, help ); break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
context.set( "data", data );
|
|
61
|
+
|
|
62
|
+
if( msg.count >= node.minData )
|
|
63
|
+
{
|
|
64
|
+
switch( node.algo )
|
|
65
|
+
{
|
|
66
|
+
case "mean": msg.payload /= msg.count; break;
|
|
67
|
+
}
|
|
68
|
+
node.status({fill:"green",shape:"dot",text:msg.payload});
|
|
69
|
+
send( msg );
|
|
70
|
+
}
|
|
71
|
+
else
|
|
72
|
+
{
|
|
73
|
+
node.status({fill:"gray",shape:"dot",text:"to less data"});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else
|
|
77
|
+
{
|
|
78
|
+
node.status({fill:"red",shape:"dot",text:"payload is NaN"});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
done();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
RED.nodes.registerType("reduce",ReduceNode);
|
|
86
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mschaeffler/node-red-logic",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "nodes for simple mathematical operations.",
|
|
5
5
|
"license": "LGPL-2.1",
|
|
6
6
|
"homepage": "https://github.com/m-schaeffler/node-red-my-nodes/tree/main/node-red-logic",
|
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
"node-red": {
|
|
18
18
|
"version": ">=1.3.7",
|
|
19
19
|
"nodes": {
|
|
20
|
+
"tobool":"logic_bool.js",
|
|
21
|
+
"tonumber":"math_number.js",
|
|
20
22
|
"or":"logic_or.js",
|
|
21
23
|
"and":"logic_and.js",
|
|
22
|
-
"tobool":"logic_bool.js",
|
|
23
24
|
"counter":"counter.js",
|
|
24
|
-
"
|
|
25
|
+
"reduce":"math_reduce.js"
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
28
|
"author": {
|
package/math_plus.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
module.exports = function(RED) {
|
|
2
|
-
|
|
3
|
-
function PlusNode(config) {
|
|
4
|
-
RED.nodes.createNode(this,config);
|
|
5
|
-
//this.config = config;
|
|
6
|
-
var node = this;
|
|
7
|
-
var context = this.context();
|
|
8
|
-
this.property = config.property || "payload";
|
|
9
|
-
this.minData = Number( config.minData );
|
|
10
|
-
|
|
11
|
-
node.on('input', function(msg,send,done) {
|
|
12
|
-
const payload = Number( RED.util.getMessageProperty( msg, node.property ) );
|
|
13
|
-
|
|
14
|
-
let data = context.get( "data" ) ?? {};
|
|
15
|
-
data[msg.topic] = payload;
|
|
16
|
-
context.set( "data", data );
|
|
17
|
-
|
|
18
|
-
msg.payload = 0;
|
|
19
|
-
let count = 0;
|
|
20
|
-
for( const item in data )
|
|
21
|
-
{
|
|
22
|
-
count++;
|
|
23
|
-
msg.payload += data[item];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if( count >= node.minData )
|
|
27
|
-
{
|
|
28
|
-
node.status( msg.payload );
|
|
29
|
-
send( msg );
|
|
30
|
-
}
|
|
31
|
-
else
|
|
32
|
-
{
|
|
33
|
-
node.status( "waiting for data" );
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
done();
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
RED.nodes.registerType("plus",PlusNode);
|
|
41
|
-
}
|