Get specific MQTT topic from an array

I have a device transmitting two temperatures (actual and setpoint) formatted as an Influx-friendly array:

and as you can see from the above, I am also using MQTT to send the array of data.

Here is Node-RED on a different PC:

My plan is to use Grafana's MQTT plugin (which I have configured, and which accepts a given MQTT topic) to display a live feed of the Actual temperature (1549 in my example above).

How do I get the topic for that one item in the array? Simply putting the full topic A1temperature brings in the whole array, which Grafana does not know what to do with. In their example below, the topic is millisecond/100

It may help if you post the message (please post correctly) and people can see it rather than looking at the screen shots.

If you have a look in the debug window and hover with your mouse - you will see that next to the value you are interested in there is a couple of icons - one of which will show you the full path to the msg property you are interested in.

In your case it looks like msg.0.0.temperature so a couple of ways you could do it.

With your incoming mqtt node you could put a change node to move the value you are interested in (in this case 1549) into the correct field that the Grafana node expects and then send that straight back out through MQTT to the broker where the Grafana plugin is listening.

Alaternatively at the source you could send out two MQTT messages (the full one you are sending now) and then a cut down one with just the grafana info and have the grafana mqtt plugin listen to that.

I have not used this plugin - usually Grafana is used to query a DB - most notably Influx.

Would it not make more sense to insert the values into Influx and then just have a grafana dashboard that looks at that DB ? THis way you would have the values available for future analysis


Thank you @craigcurtin

It was a long day yesterday and my mind was kinda clouded at that point. Your solutions make total sense and I will implement today and report back.

Just some backgound....I have been using the classic NR --> Influx --> Grafana setup for a few years now. I migrated to Influx2.0 a few months ago and cleaned up / redid all my field names, organized logical tags, etc. This is why I format the actual & setpoint data in an array (and also tag the equipment type, equipment number, etc). I typically record values to Influx once a minute. So all is good on the Influx front.

Last summer, Grafana Labs released (in beta) an MQTT datasource plugin that accepts a given topic. I finally got the plugin installed yesterday and it worked perfectly for displaying "live" data (e.g. a scale that has material moving over it, and thus is constantly changing). When I got to the part about giving it an MQTT topic, it dawned on me that my topic in the setpoint/actual temperature case was an array with a lot more data than just 1 value. I messed around with it for a bit, but kept getting wrong or bad data, and eventually figured I would post my question. Your answers are perfect and I'll get it going today.

Easy peasy....Thanks @craigcurtin

Good one - thanks for letting us know.

Also thanks for the info re the MQTT plugin - makes sense for something like a live view of a scale


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