# MQTT + Calculus + Node-red Dashboard

**URL:** <https://discourse.nodered.org/t/mqtt-calculus-node-red-dashboard/13616>\
**Category:** General\
**Created:** [23 July 2019 17:51 UTC](https://discourse.nodered.org/t/mqtt-calculus-node-red-dashboard/13616 "2019-07-23T17:51:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![NatanST](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@NatanST](https://discourse.nodered.org/u/NatanST)\
**Post date:** [23 July 2019 17:51 UTC](https://discourse.nodered.org/t/mqtt-calculus-node-red-dashboard/13616/1 "2019-07-23T17:51:14Z")

</div>

Hello,

I've been watching a lot of your tutorials lately. Unfortunately, I have a lot of doubts if what I need to do is "doable" with MQTT + Node red.

I'll try to explain in a simple way: I'm using a Software from Pozyx to get some coordinates from a RFID device. This software sends a payload via MQTT with some info (coordinates, timestamp, acceleration and blablabla). What I need to do is: receive this info, filter the payload to get only the coordinates, apply these coordinates in some matrix calculus (pure math) and show the result of the matrix in a dashboard.

What I was able to do: establish a broker to transfer the data via MQTT, connect my MQTT to my node-red "ambient", receive this payload and filter it to get only the coordinates.

Finally, my doubt is: is it possible to make the calculus on the node-red ambient or I need to run a nodejs server, send the info from my mqtt to the nodejs, do the calculation and then send it to node-red dashboard?

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [23 July 2019 18:22 UTC](https://discourse.nodered.org/t/mqtt-calculus-node-red-dashboard/13616/2 "2019-07-23T18:22:00Z")

</div>

You can do math easely. It is pure JavaScript so using function node for more complex calculations is usually the correct choice

---

<div class="post-metadata">

**Author:** ![NatanST](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@NatanST](https://discourse.nodered.org/u/NatanST)\
**Post date:** [27 August 2019 17:55 UTC](https://discourse.nodered.org/t/mqtt-calculus-node-red-dashboard/13616/3 "2019-08-27T17:55:34Z")

</div>

Hi!

I believe I can do everything that I need with these two addons, as you said:

> **[node-red-contrib-string](https://flows.nodered.org/node/node-red-contrib-string)**
>
> Provides a string manipulation node with a chainable UI based on the concise and lightweight stringjs.com.

> **[node-red-contrib-calculate](https://flows.nodered.org/node/node-red-contrib-calculate)**
>
> A calculating node for node-red

I just have one question and you probably now the answer. This is my payload after a function to filter it:

> "{"coordinates":{"x":4834,"y":1549,"z":2529},"tagId":"26398","timestamp":1566927415.462}"
> 
> _"{"coordinates":{"x":348,"y":756,"z":1264},"tagId":"26459","timestamp":1566927415.533}"_
> 
> "{"coordinates":{"x":4785,"y":1719,"z":2675},"tagId":"26398","timestamp":1566927415.581}"

What I want to get is the "X" and the "tagId" of this "X". For example, I want to show in my dashboard this:

> tagId = 26398; X = 4834
> 
> tagId = 26459; X = 348
> 
> tagId = 26398; X = 4785

I could split my coordinates and get only the "X" value, but I can't keep the "X value" and the "tagId" at the same time using the split (function string). Can you help me?

Thanks!

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [27 August 2019 18:11 UTC](https://discourse.nodered.org/t/mqtt-calculus-node-red-dashboard/13616/4 "2019-08-27T18:11:50Z")

</div>

That payload is a string if you pass it through a JSON node it should convert it to a javascript object which you can manipulate with Node-RED

If you then send it to a debug node the page in the docs called “working with messages” will show you some neat tips of how to get the path to any piece of data you want

---

<div class="post-metadata">

**Author:** ![NatanST](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@NatanST](https://discourse.nodered.org/u/NatanST)\
**Post date:** [27 August 2019 19:04 UTC](https://discourse.nodered.org/t/mqtt-calculus-node-red-dashboard/13616/5 "2019-08-27T19:04:01Z")

</div>

![issue](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/ffda3eb18a255786784f8a4b782828e9ce49795c.png)

Thank you for the "working with messages", it really helped. I was able to split my payload, exactly the way I want. My only problem is: I want to split the "object", I mean, I receive the payload from two different sensors, each one with one tagId and one X coordinates. I want to keep the pair together and compare these two... I don't know how to "split" the X from the rest and maintain the relation with the tagId.

![pair](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/da1520f79f366ea1775a554097bf7d481d840f5a.png)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [27 August 2019 19:11 UTC](https://discourse.nodered.org/t/mqtt-calculus-node-red-dashboard/13616/6 "2019-08-27T19:11:02Z")

</div>

not quite clear what you want but you could use a change node to move the parts around a bit if you like... eg move msg.payload.tagId to msg.tagId and also move msg.payload.coordinates.x to msg.payload - then you would just have the two parts on the msg (as the x would have now replaced the rest of the payload).

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 August 2019 19:20 UTC](https://discourse.nodered.org/t/mqtt-calculus-node-red-dashboard/13616/7 "2019-08-27T19:20:29Z")

</div>

> [@NatanST](#):
>
> I receive the payload from two different sensors, each one with one tagId and one X coordinates. I want to keep the pair together and compare these two... I don't know how to "split" the X from the rest and maintain the relation with the tagId.

What _exactly_ do you want to show on the dashboard. Give an example of messages received and what you want to see.

---

<div class="post-metadata">

**Author:** ![NatanST](https://avatars.discourse-cdn.com/v4/letter/n/278dde/32.png) [@NatanST](https://discourse.nodered.org/u/NatanST)\
**Post date:** [27 August 2019 19:31 UTC](https://discourse.nodered.org/t/mqtt-calculus-node-red-dashboard/13616/8 "2019-08-27T19:31:37Z")

</div>

Guys, I'm really sorry if I didn't make it quite clear. Let's try again:

This is what I want to show in my dashboard  
 ![example](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/da8eb1c68e6101ebfb836a21b37c9a6de2d9b873.png)

The main idea is: I'll put a sensor in a position and I'll have this position. For example, my sensor 01 (tagId 24555) will be at X = 30. The another sensor (02 - tagId 23859) I'll install at X = 60. What I need to do with my dashboard is: read the tagId (in order to know about which sensor I'm getting the X) and compare with my default value.

I mean: Sensor 01 (tagId 24555) was installed at X = 30. If my dashboard shows that my tagId 24555 is with X 45, I'll know that something wrong happened.

I hope that you guys can understand now, thank you a lot for all the effort 🙂

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 August 2019 19:50 UTC](https://discourse.nodered.org/t/mqtt-calculus-node-red-dashboard/13616/9 "2019-08-27T19:50:06Z")

</div>

The easiest way to get that going is probably to use dashboard Text nodes for the two columns. You can use a Switch node to send the messages down different paths to the individual text nodes. In the switch node you can test for msg.payload.tagId == string 26459 and send that message to output 1, if it is 26398 send it to output 2, and so on.
