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

[{"id":"7059e752.ba47e8","type":"csv","z":"dbbf423c.35683","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"","skip":"0","x":370,"y":220,"wires":[["45f03c3b.3d11b4"]]},{"id":"23db2011.f0b93","type":"inject","z":"dbbf423c.35683","name":"","topic":"","payload":"22.4,35,54,23","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":220,"wires":[["7059e752.ba47e8"]]},{"id":"45f03c3b.3d11b4","type":"split","z":"dbbf423c.35683","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"key","x":530,"y":220,"wires":[["73d8a91f.f83e48"]]},{"id":"73d8a91f.f83e48","type":"switch","z":"dbbf423c.35683","name":"","property":"key","propertyType":"msg","rules":[{"t":"eq","v":"col1","vt":"str"},{"t":"eq","v":"col2","vt":"str"},{"t":"eq","v":"col3","vt":"str"},{"t":"eq","v":"col4","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":690,"y":220,"wires":[["a57fb69d.de5088"],["7876e7a.185fe18"],["e03e58f3.bc5ad8"],["d1ae5d63.ed902"]]},{"id":"a57fb69d.de5088","type":"debug","z":"dbbf423c.35683","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":180,"wires":[]},{"id":"7876e7a.185fe18","type":"debug","z":"dbbf423c.35683","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":220,"wires":[]},{"id":"e03e58f3.bc5ad8","type":"debug","z":"dbbf423c.35683","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":260,"wires":[]},{"id":"d1ae5d63.ed902","type":"debug","z":"dbbf423c.35683","name":"4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":300,"wires":[]}]
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.