I want to build an array in a Node Red function block, similar to the technique in PacControl using the command ShiftNumTableElements. I am reading a float variable from the S2 Controller, which represents the weight of a tank, and from this array I want to perform various calculations such as rate of depletion from the tank, etc.
[{"id":"b569cff6.885ac8","type":"inject","z":"c97af0fa.6fb9","name":"","topic":"","payload":"","payloadType":"date","repeat":"10","crontab":"","once":false,"onceDelay":0.1,"x":473,"y":283,"wires":[["98c5637a.61f638"]]},{"id":"98c5637a.61f638","type":"pac-read","z":"c97af0fa.6fb9","device":"31b5623c.c2558e","dataType":"float-variable","tagName":"WT4101_Final","tableStartIndex":"","tableLength":"","value":"","valueType":"msg.payload","topic":"","topicType":"none","name":"","x":673,"y":289,"wires":[["4fbb0564.b4ce9c"]]},{"id":"5ee4f3dc.f1b194","type":"debug","z":"c97af0fa.6fb9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1027,"y":290,"wires":[]},{"id":"4fbb0564.b4ce9c","type":"function","z":"c97af0fa.6fb9","name":"","func":"var feed_tank_wt = msg.payload; //the new feed tank wieght from the opto controller\nvar tank_wtarray = []; //array holding the feed tank wieghts\nvar feed_rate;\n\ntank_wtarray.unshift(feed_tank_wt);\n\n//feed_rate = tank_wtarray[30] - tank_wtarray[0];\n\nmsg.payload = tank_wtarray;\n\nreturn msg;","outputs":1,"noerr":0,"x":870,"y":289,"wires":[["5ee4f3dc.f1b194"]]},{"id":"31b5623c.c2558e","type":"pac-device","z":"","address":"10.0.4.10","protocol":"http"}]
Please see flow attached. I am using the javascript “unshift” command to enter a new value at element zero of the array. However the values do not shift from there, and I continue to see only one value at 0?
Can anyone with javascript experience provide some insight on this? thanks, much appreciated. Also I realize i can do this in the S2 controller, however it is running a process and I do not want to restart it right now.