node-red-contrib-buffer-array 1.1.0
Node-RED node to fill an ring buffer array.
node-red-contrib-buffer-array
Node-RED node to fill an ring buffer array.
This node fills an array of a given length with payload values.
Motivation
Sometimes it's helpful to buffer some values of a sensor payload stream. This could be the case, if your output device is slower than your sensor data input stream. If you don't want to miss values in between the velocity gap of input and output devices (Nyquist–Shannon sampling theorem), you can use the value buffer to calculate the average of the last few values.
Installation
This package uses ES2015 code. Therefore use at least version 6.4.0 of Node.js.
This package is a node for Node-RED. Install Node-RED
Install this package:
npm install node-red-contrib-buffer-array
... or use the palette manager of the Node-RED ui.
Nodes
buffer-array
Input
payload any
Output
payload array
the buffer array of a given length containing a collection of payloads (added from right to left).
Details
The input payload will be added to the end of the output array. The array has a defined length of items. The first item is the oldest value and the last one is the newest.
If you use numeric values, you'll be able to get the average value of the payloads inside the array. To get the average
value, you might attach a standard change node to set a variable with the expression $average(payload)
.
Of course, you might use other expressions like $max(payload)
to get the maximum value of the collected
payloads, etc.
If you check the option Starting output when buffer filled
the node will not output anything until the array is filled
completely. I.e. if the buffer array has a length of 6 items, the first 5 node calls will not lead to an output of an
buffer array. The 6th call will output the filled buffer array with all 6 items.
Flows
Example flow:
[{"id":"feddb213.294f9","type":"buffer-array","z":"cc8d16aa.a75d28","name":"","bufferLen":"5","startWhenFilled":false,"x":490,"y":160,"wires":[["537c7a24.a841a4","7ccad598.17429c"]]},{"id":"1468aa76.c77d06","type":"random","z":"cc8d16aa.a75d28","name":"","low":"1","high":"10","inte":"true","property":"payload","x":300,"y":160,"wires":[["feddb213.294f9"]]},{"id":"a9da101a.14cf9","type":"inject","z":"cc8d16aa.a75d28","name":"","topic":"test","payload":"Hello!","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":220,"wires":[["feddb213.294f9"]]},{"id":"537c7a24.a841a4","type":"debug","z":"cc8d16aa.a75d28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":670,"y":160,"wires":[]},{"id":"7ccad598.17429c","type":"change","z":"cc8d16aa.a75d28","name":"Get Average","rules":[{"t":"set","p":"payload","pt":"msg","to":"$average(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":200,"wires":[["58fb2cf.d406ad4"]]},{"id":"7ec722b3.ebeedc","type":"inject","z":"cc8d16aa.a75d28","name":"","topic":"random","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":160,"wires":[["1468aa76.c77d06"]]},{"id":"58fb2cf.d406ad4","type":"debug","z":"cc8d16aa.a75d28","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":830,"y":200,"wires":[]}]