1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Let RBE node handle multiple msg.topic at the same time.

This commit is contained in:
dceejay 2015-06-29 17:29:12 +01:00
parent 04f43851e5
commit 3f08764dd4
4 changed files with 13 additions and 7 deletions

View File

@ -18,6 +18,9 @@ Usage
A simple node to provide report by exception (RBE) and deadband function
- only passes on data if it has changed.
This works on a per **msg.topic** basis. This means that a single rbe node can
handle multiple topics at the same time.
###RBE mode
Outputs the **msg** if the **msg.payload** is different to the previous one.

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-rbe",
"version" : "0.0.4",
"version" : "0.0.5",
"description" : "A Node-RED node that provides report-by-exception (RBE) and deadband capability.",
"dependencies" : {
},

View File

@ -38,6 +38,8 @@
different to the previous one. Works on numbers and strings.</p>
<p>In <b>deadband</b> mode the incoming payload should contain a parseable <i>number</i> and is
output only if greater than + or - the <i>band gap</i> away from the previous output.</p>
<p><b>Note:</b> This works on a per <b>msg.topic</b> basis. This means that a single rbe node can
handle multiple topics at the same time.</p>
</script>
<script type="text/javascript">

View File

@ -23,21 +23,22 @@ module.exports = function(RED) {
this.gap = n.gap || 0;
var node = this;
var previous = null;
node.previous = {};
this.on("input",function(msg) {
if (msg.hasOwnProperty("payload")) {
var t = msg.topic || "_no_topic";
if (this.func === "rbe") {
if (msg.payload != previous) {
previous = msg.payload;
if (msg.payload != node.previous[t]) {
node.previous[t] = msg.payload;
node.send(msg);
}
}
else {
var n = parseFloat(msg.payload);
if (!isNaN(n)) {
if (previous == null) { previous = n - node.gap; }
if (Math.abs(n - previous) >= node.gap) {
previous = n;
if (!node.previous.hasOwnProperty(t)) { node.previous[t] = n - node.gap; }
if (Math.abs(n - node.previous[t]) >= node.gap) {
node.previous[t] = n;
node.send(msg);
}
}