Mathematical calculations

I have tried to follow the Help section & previous topics, but I am still stuck ...

In order to calculate the current volume of oil in a horizontal cylindrical tank I need to process several mathematical calculations in turn. Rather than try to do everything in one go, I have broken these down in to series of discrete "sums" using function nodes. So far so good.

But I can't work out the syntax to put in a function Node d manipulating the output of two others, eg, "the result of function Node b minus the result of function Node c "

How might I phrase this? I am not sure how to identify the previous output of a function node and put it in to another node for further processing.

Many thanks!

Sounds like you may want to look at saving values then pull them back in when you need them. Look at using flow.save , you should find this in node red docs.

You may also want to look at node-red-contrib-tank-volume - npm as it may help

1 Like

You can join the outputs of the two function nodes with a join node like this

[{"id":"c48f46e577eaf844","type":"function","z":"a3e369ffd4e1629e","name":"","func":"msg.payload = 27;\nmsg.topic = \"topic1\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":120,"wires":[["6c4f6e5cbee8072a"]]},{"id":"3a263e81ac6bd039","type":"function","z":"a3e369ffd4e1629e","name":"","func":"msg.payload = 5;\nmsg.topic = \"topic2\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":160,"wires":[["6c4f6e5cbee8072a"]]},{"id":"6c4f6e5cbee8072a","type":"join","z":"a3e369ffd4e1629e","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":490,"y":140,"wires":[["398e5fefd1268494","3c35d0d4665504b7"]]},{"id":"398e5fefd1268494","type":"function","z":"a3e369ffd4e1629e","name":"","func":"msg.payload = msg.payload.topic1 + msg.payload.topic2;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":140,"wires":[["7aad460a950c31d3"]]},{"id":"2469c14de3faaafc","type":"inject","z":"a3e369ffd4e1629e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":120,"wires":[["c48f46e577eaf844"]]},{"id":"3dbb85870f589efb","type":"inject","z":"a3e369ffd4e1629e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":160,"wires":[["3a263e81ac6bd039"]]},{"id":"7aad460a950c31d3","type":"debug","z":"a3e369ffd4e1629e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":140,"wires":[]},{"id":"3c35d0d4665504b7","type":"debug","z":"a3e369ffd4e1629e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":100,"wires":[]}]

And the node @dceejay mentioned is introduced here

2 Likes

Put the calculations one after another, not in parallel. Then it is much easier.

1 Like

"Great minds" think alike. I had this all set to post, honest.

[{"id":"754ed93fca304316","type":"inject","z":"1a062a4d47b6ea5b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":1140,"wires":[["0de4747b872883fb"]]},{"id":"0de4747b872883fb","type":"function","z":"1a062a4d47b6ea5b","name":"","func":"msg.a = 27;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":1140,"wires":[["540bb50f4da2ae71"]]},{"id":"540bb50f4da2ae71","type":"function","z":"1a062a4d47b6ea5b","name":"","func":"msg.b = 5;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":1140,"wires":[["251b9bc5bc098a8b"]]},{"id":"251b9bc5bc098a8b","type":"function","z":"1a062a4d47b6ea5b","name":"","func":"msg.payload = msg.a + msg.b;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1140,"wires":[["57e15183b4acee15"]]},{"id":"57e15183b4acee15","type":"debug","z":"1a062a4d47b6ea5b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":1140,"wires":[]}]