Multiplication function or similar

Hi all.
I want to multipicate two different RANDOM nodes to use the multiplication result in another node.
How can i implement this function?

What do you mean by RANDOM nodes? Do you mean a particular node type that you have installed?

If you mean that you have two messages coming in from different nodes and you want to join the messages so that you can use data from both nodes in a function node (for example) then have a look at the example in the cookbook on joining streams.
https://cookbook.nodered.org/basic/join-streams

Hi and thanks for your reply.
I've just read your link but i think it doesn't help me.
You can see attached my flow.
Instead of the JOIN node i would to use a multiplication node or similar.
How can implement it?

[{"id":"24529235.0f95ae","type":"tab","label":"Multiplication","disabled":false,"info":""},{"id":"fb705d35.038ff","type":"ui_chart","z":"24529235.0f95ae","name":"","group":"31de20bd.63b6c","order":1,"width":0,"height":0,"label":"Tensione [V]","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"250","removeOlder":"180","removeOlderPoints":"","removeOlderUnit":"1","cutout":0,"useOneColor":false,"colors":["#00ff00","#aec7e8","#ff581c","#2ca02c","#98df8a","#7ff21b","#ff9896","#7cf5a2","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":805,"y":126,"wires":[[]]},{"id":"b4df74d8.46c978","type":"random","z":"24529235.0f95ae","name":"Tensione","low":"215","high":"225","inte":"true","property":"payload","x":396,"y":168,"wires":[["fb705d35.038ff","c3ddab68.cd52d8","65a88d12.bb7e44","6357798a.e0c228"]]},{"id":"105332c0.e8260d","type":"inject","z":"24529235.0f95ae","name":"","topic":"Tensione","payload":"1","payloadType":"num","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":154,"y":168,"wires":[["b4df74d8.46c978"]]},{"id":"b6a79024.a0608","type":"random","z":"24529235.0f95ae","name":"Corrente","low":"5","high":"20","inte":"true","property":"payload","x":375,"y":231,"wires":[["58d168ef.117d58","2f65c37a.86dc9c","65a88d12.bb7e44"]]},{"id":"9943c87f.d52f98","type":"inject","z":"24529235.0f95ae","name":"","topic":"Corrente","payload":"1","payloadType":"num","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":154,"y":231,"wires":[["b6a79024.a0608"]]},{"id":"58d168ef.117d58","type":"ui_chart","z":"24529235.0f95ae","name":"","group":"31de20bd.63b6c","order":2,"width":0,"height":0,"label":"Corrente [A]","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"60","removeOlder":"180","removeOlderPoints":"","removeOlderUnit":"1","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#18df0a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":805,"y":252,"wires":[[]]},{"id":"cb4e6015.edf25","type":"ui_chart","z":"24529235.0f95ae","name":"","group":"31de20bd.63b6c","order":3,"width":0,"height":0,"label":"Potenza istantanea [kW]","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"60","removeOlder":"180","removeOlderPoints":"","removeOlderUnit":"1","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#e45aea","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":950,"y":420,"wires":[[]]},{"id":"58f0cb97.862454","type":"debug","z":"24529235.0f95ae","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":910,"y":336,"wires":[]},{"id":"2f65c37a.86dc9c","type":"ui_gauge","z":"24529235.0f95ae","name":"","group":"834e9290.5975f","order":2,"width":0,"height":0,"gtype":"gage","title":"Corrente","label":"units","format":"{{value}}","min":0,"max":"30","colors":["#00b500","#e6e600","#ca3838"],"seg1":"10","seg2":"20","x":795,"y":210,"wires":[]},{"id":"c3ddab68.cd52d8","type":"ui_gauge","z":"24529235.0f95ae","name":"","group":"834e9290.5975f","order":1,"width":0,"height":0,"gtype":"gage","title":"Tensione","label":"units","format":"{{value}}","min":0,"max":"230","colors":["#00b500","#e6e600","#ca3838"],"seg1":"110","seg2":"220","x":795,"y":84,"wires":[]},{"id":"65a88d12.bb7e44","type":"join","z":"24529235.0f95ae","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"bin","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":680,"y":336,"wires":[["58f0cb97.862454","cb4e6015.edf25"]]},{"id":"6357798a.e0c228","type":"debug","z":"24529235.0f95ae","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":616,"y":42,"wires":[]},{"id":"31de20bd.63b6c","type":"ui_group","z":"","name":"Gruppo3","tab":"4e9aa3f5.60126c","order":1,"disp":false,"width":10,"collapse":false},{"id":"834e9290.5975f","type":"ui_group","z":"","name":"Gruppo5","tab":"4e9aa3f5.60126c","order":2,"disp":false,"width":10,"collapse":false},{"id":"4e9aa3f5.60126c","type":"ui_tab","z":"","name":"3-Trend variabili","icon":"fa-line-chart","order":3,"disabled":false,"hidden":false}]

You need to do the Join first, then multiply the numbers, which should be available in msg.payload.
I don't know what type the Random node is, you haven't told us, but for the Join to work the two inputs must have different topics. Also you haven't told the Join node to give you a joined message after two message parts are received.

Apart from considering the solution I would be fascinated to know why you want to multiply two random numbers together.

Random node creates a random number.
I use this node to make a demo.

Might I make a suggestion, have one inject node going to two change nodes that set the msg.topic.

Also add a new join node in and replace the existing one. For some reason, the internals of the node thinks it should be doing the join using 'bin' when it should be 'str'. I've seen this happen before but thought it was something I did but I think it is a bug in the join node which I'm going to investigate.

In your case, just add a new join node, set the settings up like this:

and after the join you could use a function node or a change node to multiply the two values. Here is an example (with the dashboard info removed.) Showing what I mean:

[{"id":"ab242326.56c6c8","type":"random","z":"a340b780.deade8","name":"Tensione","low":"215","high":"225","inte":"true","property":"payload","x":400,"y":80,"wires":[["d3965c13.571df8"]]},{"id":"a6ecace0.d9f3d","type":"inject","z":"a340b780.deade8","name":"","topic":"Start","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":140,"wires":[["a4fd6efe.59b158","f777c593.0262e8"]]},{"id":"d5058fd1.e36c18","type":"random","z":"a340b780.deade8","name":"Corrente","low":"5","high":"20","inte":"true","property":"payload","x":400,"y":200,"wires":[["d3965c13.571df8"]]},{"id":"13abfe36.bce56a","type":"debug","z":"a340b780.deade8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":180,"wires":[]},{"id":"851c2a9f.e4256","type":"debug","z":"a340b780.deade8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":550,"y":180,"wires":[]},{"id":"d3965c13.571df8","type":"join","z":"a340b780.deade8","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":530,"y":140,"wires":[["befd85e3.12838","851c2a9f.e4256"]]},{"id":"befd85e3.12838","type":"change","z":"a340b780.deade8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.Tensione*payload.Corrente","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":140,"wires":[["13abfe36.bce56a"]]},{"id":"f777c593.0262e8","type":"change","z":"a340b780.deade8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Corrente","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":200,"wires":[["d5058fd1.e36c18"]]},{"id":"a4fd6efe.59b158","type":"change","z":"a340b780.deade8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Tensione","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":80,"wires":[["ab242326.56c6c8"]]}]

Also can you let me know

  • what version of NR and node.js (see node-red startup log)
  • what platform/os you are using
    Thanks

Hi and many thanks for your reply.
I've just resolved using a function node after join node.
However i save your solution for further implementation.
This is the cose used in function node:

var prodotto = {payload: msg.payload.Corrente * msg.payload.Tensione};
return prodotto;

And I figured out whet the bug is in the join node and am reporting it.

These are my system info:

Node-RED version: v1.0.3
Node.js version: v10.19.0
Linux 4.19.57+ arm LE
Raspberry model B+
Dashboard version 2.19.4 started at /ui

FYI issue raised to fix the bug see: https://github.com/node-red/node-red/issues/2491

If you do hit this issue, you can fix the node by switching the 'to create' option to 'a String' and changing the 'join using' to 'a/z' thn changing the 'to create' back to what you originally had.

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