MQTT Publish Node

In the case of using MQTT Publish Node and do some calculation(+,-,/,*..etc) on data.
How to do mathematic on data?
Should I use a change node or function node and what should I write on it?

I'm not sure with your problem. Have you tried node-red-contrib-calc? It has a lot of mathmatics functions.

Here is a simple example using a function node and one using a change node.

[{"id":"6c9fcc18.6b4dbc","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload * 10","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":2600,"wires":[["37a2b87e.56ff58"]]},{"id":"f62e5026.deaf8","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":130,"y":2620,"wires":[["6c9fcc18.6b4dbc","49eeff13.b82a28"]]},{"id":"37a2b87e.56ff58","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":540,"y":2620,"wires":[]},{"id":"49eeff13.b82a28","type":"function","z":"c74669a0.6a34f8","name":"","func":"msg.payload = msg.payload / 10;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":300,"y":2660,"wires":[["37a2b87e.56ff58"]]}]

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