# Something wrong with buffer-array node?

**URL:** <https://discourse.nodered.org/t/something-wrong-with-buffer-array-node/58938>\
**Category:** General\
**Created:** [24 February 2022 16:33 UTC](https://discourse.nodered.org/t/something-wrong-with-buffer-array-node/58938 "2022-02-24T16:33:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcos](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcos/32/18284_2.png) [@Marcos](https://discourse.nodered.org/u/Marcos)\
**Post date:** [24 February 2022 16:33 UTC](https://discourse.nodered.org/t/something-wrong-with-buffer-array-node/58938/1 "2022-02-24T16:33:33Z")

</div>

Dear All  
Thanks for your attention. I’ve spent all this day trying to understand what is wrong with the buffer-array node. It is supposed that this node, receiving any payload in input, will output an array payload of a specified length.  
Here following the proposed example flow.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/521ea36832890f5f553812db03f390d79742e980.png)  
In the above example, it is supposed to have a 2 item length array.  
Everything is how expected in general.  
At the first inject, because the “starting output when buffer filled” option is flagged, it waits for a second input  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/2/f259b86d1e10f81508b75e7f449b9416824fe0aa.png)  
At the second inject it emits its first array payload  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/4/1420275f9f7cfaae277ea602b6c9519aa2a0ee74.jpeg)  
At the third inject  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/c/7ca855b260698b39914273e86be7a50f652623a9.jpeg)  
And so on.  
At every inject the array payload will have always 2 items length.  
If I start to make some little implementations, the situation suddenly changes for apparently no reason.  
Let’s consider the following flow  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c46b726118f0b8b36ed284bd882cb2f433ba1730.jpeg)  
To quick check, I’ve added the highlighted inject node.  
Starting to inject timestamps I have the following  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/7699a22d7b2b21b56ba614826c52b954a6086998.jpeg)  
As you can see, the number of items inside the array grows at every injection.  
I’ve tried many things to fix this but there is no way for me. I can state that in both cases (I have twin nodes that have different behaviours) I use the same payload as input but the output is different.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/b/9b4805d96bd72b07d444902f2504ab6f33f89707.jpeg)  
What do you suggest?  
Here is the code

```auto
[{"id":"32a351812dc774c6","type":"buffer-array","z":"dd8988faf814e6f7","name":"buffer-array","bufferLen":"2","startWhenFilled":true,"x":3210,"y":200,"wires":[["3dce74707d0be026","7ccad598.17429c"]]},{"id":"c70a04ed45b1aee3","type":"calculator","z":"dd8988faf814e6f7","name":"","inputMsgField":"payload","outputMsgField":"payload","operation":"sub","constant":"0","round":true,"decimals":"2","x":3260,"y":520,"wires":[["02dcb965ae471430"]]},{"id":"02dcb965ae471430","type":"function","z":"dd8988faf814e6f7","name":"Funz Adattamento","func":"//da millisecondi a secondi a secondi \nmsg.payload=(msg.payload/(1000)*(-1)) \n//inserito il fattore di correzione -1 perchè la sottrazione \n//produce sempre valori negativi essendo T1-T2 con T1<T2\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3290,"y":560,"wires":[["828d27805f8da3a7"]]},{"id":"828d27805f8da3a7","type":"join","z":"dd8988faf814e6f7","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":3650,"y":560,"wires":[["2d2023943246dbad"]]},{"id":"e9444bab77f88b73","type":"calculator","z":"dd8988faf814e6f7","name":"","inputMsgField":"payload","outputMsgField":"payload","operation":"sum","constant":"0","round":true,"decimals":"2","x":3470,"y":440,"wires":[["572dccec5eadf1e1"]]},{"id":"190e5ba73fc621f5","type":"change","z":"dd8988faf814e6f7","name":"","rules":[{"t":"delete","p":"time","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":3500,"y":520,"wires":[["828d27805f8da3a7"]]},{"id":"572dccec5eadf1e1","type":"function","z":"dd8988faf814e6f7","name":"Media","func":"msg.payload=msg.payload/2\n//msg.payload=msg.payload\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3470,"y":480,"wires":[["190e5ba73fc621f5"]]},{"id":"a600b0d3f2b69208","type":"buffer-array","z":"dd8988faf814e6f7","name":"buffer values array","bufferLen":"2","startWhenFilled":true,"x":3510,"y":400,"wires":[["e9444bab77f88b73"]]},{"id":"e3960ce933340533","type":"change","z":"dd8988faf814e6f7","name":"","rules":[{"t":"set","p":"time","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":3270,"y":400,"wires":[["4df730e41c3d0dd8","a600b0d3f2b69208"]]},{"id":"4df730e41c3d0dd8","type":"change","z":"dd8988faf814e6f7","name":"","rules":[{"t":"move","p":"time","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"time","pt":"msg"},{"t":"set","p":"topic","pt":"msg","to":"time","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3280,"y":440,"wires":[["5e78c311bab8325a"]]},{"id":"7755103db1de0916","type":"function","z":"dd8988faf814e6f7","name":"da mc/h a l/s","func":"A= msg.payload;\nB = A *(1000/3600)\nmsg.payload=B;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3070,"y":400,"wires":[["e3960ce933340533"]]},{"id":"bd638e66da3b01d3","type":"inject","z":"dd8988faf814e6f7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":2820,"y":400,"wires":[["7755103db1de0916"]]},{"id":"2d2023943246dbad","type":"calculator","z":"dd8988faf814e6f7","name":"","inputMsgField":"payload","outputMsgField":"payload","operation":"mult","constant":"1","round":true,"decimals":"2","x":3660,"y":600,"wires":[[]]},{"id":"1468aa76.c77d06","type":"random","z":"dd8988faf814e6f7","name":"","low":"1","high":"10","inte":"false","property":"payload","x":3040,"y":160,"wires":[["32a351812dc774c6"]]},{"id":"7ccad598.17429c","type":"change","z":"dd8988faf814e6f7","name":"Get Average","rules":[{"t":"set","p":"payload","pt":"msg","to":"$average(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":3390,"y":240,"wires":[["58fb2cf.d406ad4"]]},{"id":"7ec722b3.ebeedc","type":"inject","z":"dd8988faf814e6f7","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"random","payload":"","payloadType":"date","x":2850,"y":160,"wires":[["1468aa76.c77d06"]]},{"id":"58fb2cf.d406ad4","type":"debug","z":"dd8988faf814e6f7","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":3550,"y":240,"wires":[]},{"id":"3dce74707d0be026","type":"debug","z":"dd8988faf814e6f7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":3370,"y":200,"wires":[]},{"id":"a455ed7de9940b11","type":"inject","z":"dd8988faf814e6f7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":2820,"y":300,"wires":[["5e78c311bab8325a","32a351812dc774c6"]]},{"id":"a9da101a.14cf9","type":"inject","z":"dd8988faf814e6f7","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"test","payload":"Hello!","payloadType":"str","x":2920,"y":220,"wires":[["32a351812dc774c6"]]},{"id":"5e78c311bab8325a","type":"buffer-array","z":"dd8988faf814e6f7","name":"","bufferLen":"2","startWhenFilled":true,"x":3270,"y":480,"wires":[["c70a04ed45b1aee3","7571b89928495d78"]]},{"id":"7571b89928495d78","type":"debug","z":"dd8988faf814e6f7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":3510,"y":360,"wires":[]}]

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [26 February 2022 12:18 UTC](https://discourse.nodered.org/t/something-wrong-with-buffer-array-node/58938/2 "2022-02-26T12:18:23Z")

</div>

Sorry I don't use this node - but there is an alternative you could look at - [ring-buffer](https://flows.nodered.org/node/node-red-contrib-ring-buffer)

---

<div class="post-metadata">

**Author:** ![Marcos](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcos/32/18284_2.png) [@Marcos](https://discourse.nodered.org/u/Marcos)\
**Post date:** [22 March 2022 08:41 UTC](https://discourse.nodered.org/t/something-wrong-with-buffer-array-node/58938/3 "2022-03-22T08:41:59Z")

</div>

Definitely, no way to make buffer-array work properly.  
Thanks to smcgann99 for having pointed out ring-buffer that works well.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 April 2022 08:42 UTC](https://discourse.nodered.org/t/something-wrong-with-buffer-array-node/58938/4 "2022-04-05T08:42:58Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
