MQTT + Calculus + Node-red Dashboard

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?

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

2 Likes

Hi!

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

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!

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

1 Like

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

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).

1 Like

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

1 Like

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

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 :slight_smile:

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.

1 Like