String data from mqtt to gauges

Guys I am using an mqtt node to send sensor data(4sensors) and to reduce packet size, I am sending the values as a string. Eg: "22.4,35,54,23". I need to extract this data and need to display them in 4 different charts. But I am not able to convert the data to the required format. Can anyone please help me on this, please....

This could work for you

1 Like

It really is not worth doing that unless you have an unusual requirement. The amount you save will be trivial, and the complexity added to everything else will not be trivial (which is obvious since you have had to ask how to do it). It is much easier to send them to separate named topics.

1 Like

Actually there is a requity. We are integrating the info into infuxDB, which inturn is being used for displaying in grafana and influx takes data in this format.

I don't think so, the usual way is to supply it with a javascript objects where the property names are the fields to be written to. Assuming you are using it that way you could send the values as a json string, then you would just need to feed it through a JSON node and straight to influx. Providing identification embedded in the data makes for a much more robust system as you don't need both ends (and anything else that at some point might subscribe to the MQTT topic to know what order the data items are in. However, that is up to you obviously.

But how can we supply the data straight to influx in node-red?

If it is formatted correctly then you can just feed it into an influxdb node. So if you published to mqtt a string something like

{"field1": 22.4, "field2": 35}

then when that is picked up you can pass that through a JSON node which will convert it to the equivalent js object, then just pass that to the influx node.
Similarly to send a value to a gauge you can use a Change node to Move msg.payload.field1 To msg.payload and feed that to the gauge.

or just feed the existing string through a csv node to turn it into an object with property names.