From c890ca57d5820c509d0b49dcf9555b5dedfd1f0b Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Tue, 27 Apr 2021 20:25:30 +0100 Subject: [PATCH] Let RBE node be able to use any property as key (not just topic) (not for publish until 2.0) --- function/rbe/locales/en-US/rbe.html | 6 +++--- function/rbe/locales/en-US/rbe.json | 2 +- function/rbe/package.json | 2 +- function/rbe/rbe.html | 6 ++++-- function/rbe/rbe.js | 12 +++++++++--- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/function/rbe/locales/en-US/rbe.html b/function/rbe/locales/en-US/rbe.html index 0bca2cf0..db63cb0d 100644 --- a/function/rbe/locales/en-US/rbe.html +++ b/function/rbe/locales/en-US/rbe.html @@ -10,7 +10,7 @@ Other modes must provide a parseable number.
topic string
-
if specified the function will work on a per topic basis.
+
if specified the function will work on a per topic basis. This property can be set by configuration.
resetany
if set clears the stored value for the specified msg.topic, or all topics if msg.topic is not specified.
@@ -26,7 +26,7 @@

In RBE mode this node will block until the msg.payload, (or selected property) value is different to the previous one. If required it can ignore the intial value, so as not to send anything at start.

-

The Deadband modes will block the incoming value +

The Deadband modes will block the incoming value unless its change is greater or greater-equal than ± the band gap away from a previous value.

The Narrowband modes will block the incoming value, if its change is greater or greater-equal than ± the band gap away from the previous value. @@ -36,6 +36,6 @@

Both Deadband and Narrowband allow comparison against either the previous valid output value, thus ignoring any values out of range, or the previous input value, which resets the set point, thus allowing gradual drift (deadband), or a step change (narrowband).

-

Note: This works on a per msg.topic basis. +

Note: This works on a per msg.topic basis, though this can be changed to another property if desired. This means that a single rbe node can handle multiple different topics at the same time.

diff --git a/function/rbe/locales/en-US/rbe.json b/function/rbe/locales/en-US/rbe.json index 0a493e3a..7dc275e0 100644 --- a/function/rbe/locales/en-US/rbe.json +++ b/function/rbe/locales/en-US/rbe.json @@ -6,7 +6,7 @@ "init": "Send initial value", "start": "Start value", "name": "Name", - "septopics": "Apply mode for each msg.topic separately" + "septopics": "Apply mode separately for each " }, "placeholder":{ "bandgap": "e.g. 10 or 5%", diff --git a/function/rbe/package.json b/function/rbe/package.json index eb11db4d..4d483f3c 100644 --- a/function/rbe/package.json +++ b/function/rbe/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-node-rbe", - "version" : "0.5.0", + "version" : "0.6.0", "description" : "A Node-RED node that provides report-by-exception (RBE) and deadband capabilities.", "dependencies" : { }, diff --git a/function/rbe/rbe.html b/function/rbe/rbe.html index 58a5a9be..9c484038 100644 --- a/function/rbe/rbe.html +++ b/function/rbe/rbe.html @@ -30,7 +30,7 @@
- +
@@ -49,7 +49,8 @@ start: {value:""}, inout: {value:"out"}, septopics: {value:true}, - property: {value:"payload",required:true} + property: {value:"payload",required:true}, + topi: {value:"topic",required:true} }, inputs:1, outputs:1, @@ -69,6 +70,7 @@ $("#node-input-septopics").prop('checked', true); } $("#node-input-property").typedInput({default:'msg',types:['msg']}); + $("#node-input-topi").typedInput({default:'msg',types:['msg']}); //$( "#node-input-gap" ).spinner({min:0}); if ($("#node-input-inout").val() === null) { $("#node-input-inout").val("out"); diff --git a/function/rbe/rbe.js b/function/rbe/rbe.js index c5885101..4548a8c6 100644 --- a/function/rbe/rbe.js +++ b/function/rbe/rbe.js @@ -13,7 +13,8 @@ module.exports = function(RED) { this.gap = parseFloat(this.gap); } this.g = this.gap; - this.property = n.property||"payload"; + this.property = n.property || "payload"; + this.topi = n.topi || "topic"; this.septopics = true; if (n.septopics !== undefined && n.septopics === false) { this.septopics = false; @@ -23,8 +24,13 @@ module.exports = function(RED) { node.previous = {}; this.on("input",function(msg) { + var topic; + try { + topic = RED.util.getMessageProperty(msg,node.topi); + } + catch(e) { } if (msg.hasOwnProperty("reset")) { - if (node.septopics && msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== "")) { + if (node.septopics && topic && (typeof topic === "string") && (topic !== "")) { delete node.previous[msg.topic]; } else { node.previous = {}; } @@ -32,7 +38,7 @@ module.exports = function(RED) { var value = RED.util.getMessageProperty(msg,node.property); if (value !== undefined) { var t = "_no_topic"; - if (node.septopics) { t = msg.topic || t; } + if (node.septopics) { t = topic || t; } if ((this.func === "rbe") || (this.func === "rbei")) { var doSend = (this.func !== "rbei") || (node.previous.hasOwnProperty(t)) || false; if (typeof(value) === "object") {