# MQTT Publish Node

**URL:** https://discourse.nodered.org/t/mqtt-publish-node/48952
**Category:** General
**Created:** [27 July 2021 06:46 UTC](https://discourse.nodered.org/t/mqtt-publish-node/48952 "2021-07-27T06:46:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![wael5300](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wael5300/32/44905_2.png) [@wael5300](https://discourse.nodered.org/u/wael5300)
#### Post date: [27 July 2021 06:46 UTC](https://discourse.nodered.org/t/mqtt-publish-node/48952/1 "2021-07-27T06:46:35Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![sfedo](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@sfedo](https://discourse.nodered.org/u/sfedo)
#### Post date: [27 July 2021 08:19 UTC](https://discourse.nodered.org/t/mqtt-publish-node/48952/2 "2021-07-27T08:19:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [27 July 2021 08:45 UTC](https://discourse.nodered.org/t/mqtt-publish-node/48952/3 "2021-07-27T08:45:34Z")

</div>

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

```auto
[{"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"]]}]

```

---

<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: [25 September 2021 08:45 UTC](https://discourse.nodered.org/t/mqtt-publish-node/48952/4 "2021-09-25T08:45:38Z")

</div>

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