How to split mqtt tag values

Have a two tags or more recived from mqtt broker. How to split tag from each other for seperated outputs?

Best regards

msg.payload is a string to first thing is to convert it to an object. Try running it through the JSON node. See the cookbook https://cookbook.nodered.org/
Then the page in the docs about working with messages will be worth reading

I was convert string to object. I try more method but still mixed. How i can do thatmqtt_tag_object

I assume you want msg.payload.q ?

If so, what’s creating the MQTT message as it’s coming in the wrong way round ( value, key) rather than (key, value). If you can, it might be better to fix the sender.

Unclear topic.

Do you want to split the payload, or do you want multiple outputs, 1 for each payload ?
If you want multiple outputs, the input always needs to be the same.

I'm so sorry about mistaken words .

I don't want multiple outputs for 1 each payload. I would peer to peer.

I've get two message (maybe is up to "n" in future) from mqtt broker. I was spllit payload "v" for both message at the JSON but output value switching between two payload and it's randomly!

node_red_switch_between

Broker Message template shown below

{
"timestamp": |SERVERTIMESTAMP|,
"values": [
|#each VALUES|
{"id": "|TAGNAME|", "v": |VALUE|, "q": |QUALITY|, "t": |TIMESTAMP| } |#unless @last|,|/unless|
|/each|
]
}

Please do a mqtt -> debug and post the output here.

iotgateway : msg : Object

object

topic: "iotgateway"

payload: "{"timestamp":1557554912495,"values":[{"id":"HSM1.EGD.SPR.SM\DC2000\ODAKUZ_FB","v":21.6999989,"q":true,"t":1557554904136},{"id":"HSM1.EGD.SPR.SM\DC2000\ODAGUN_FB","v":24.1999989,"q":true,"t":1557554904136},{"id":"HSM1.EGD.SPR.SM\DC2000\ODAGUN_FB","v":24.0999985,"q":true,"t":1557554905136},{"id":"HSM1.EGD.SPR.SM\DC2000\ODAKUZ_FB","v":21.3999996,"q":true,"t":1557554906136},{"id":"HSM1.EGD.SPR.SM\DC2000\ODAKUZ_FB","v":21.5999985,"q":true,"t":1557554907136},{"id":"HSM1.EGD.SPR.SM\DC2000\ODAGUN_FB","v":24.2999992,"q":true,"t":1557554908136},{"id":"HSM1.EGD.SPR.SM\DC2000\ODAGUN_FB","v":24.0999985,"q":true,"t":1557554910136},{"id":"HSM1.EGD.SPR.SM\DC2000\ODAKUZ_FB","v":21.4999981,"q":true,"t":1557554911136}]}"

qos: 1

retain: false

_msgid: "b4b34316.41302"

The \ is problematic, as it is an escape character, can those be changed to / ?

Try this flow (I have changed the backslashes to make it work with an inject node. Replace the inject node with your mqtt node and set the mqtt node to output json):

[{"id":"aee7d67a.411258","type":"inject","z":"f298621.db6eda","name":"","topic":"","payload":"{\"timestamp\":1557554912495,\"values\":[{\"id\":\"HSM1.EGD.SPR.SM/DC2000/ODAKUZ_FB\",\"v\":21.6999989,\"q\":true,\"t\":1557554904136},{\"id\":\"HSM1.EGD.SPR.SM/DC2000/ODAGUN_FB\",\"v\":24.1999989,\"q\":true,\"t\":1557554904136},{\"id\":\"HSM1.EGD.SPR.SM/DC2000/ODAGUN_FB\",\"v\":24.0999985,\"q\":true,\"t\":1557554905136},{\"id\":\"HSM1.EGD.SPR.SM/DC2000/ODAKUZ_FB\",\"v\":21.3999996,\"q\":true,\"t\":1557554906136},{\"id\":\"HSM1.EGD.SPR.SM/DC2000/ODAKUZ_FB\",\"v\":21.5999985,\"q\":true,\"t\":1557554907136},{\"id\":\"HSM1.EGD.SPR.SM/DC2000/ODAGUN_FB\",\"v\":24.2999992,\"q\":true,\"t\":1557554908136},{\"id\":\"HSM1.EGD.SPR.SM/DC2000/ODAGUN_FB\",\"v\":24.0999985,\"q\":true,\"t\":1557554910136},{\"id\":\"HSM1.EGD.SPR.SM/DC2000/ODAKUZ_FB\",\"v\":21.4999981,\"q\":true,\"t\":1557554911136}]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":352,"wires":[["7657164f.129d38"]]},{"id":"7657164f.129d38","type":"function","z":"f298621.db6eda","name":"","func":"i = msg.payload.values\n\ni.forEach((e)=>{\n\n    node.send({payload:{id:e.id, value:e.v, timestamp:e.t}})\n    \n})\n    \n\n\n\n","outputs":1,"noerr":0,"x":358,"y":352,"wires":[["6adbd054.c41878"]]},{"id":"6adbd054.c41878","type":"debug","z":"f298621.db6eda","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":532,"y":352,"wires":[]}]

Thanks for express reply. Problem solved.

I was replace backslashes with slash at the broker side.

I have seen topics debug window with below code. How to separate topic for lot of output on the function node

for(var i in msg.payload.values)
{
var newmessage = msg.payload.values[i].v;
var newtopic = msg.topic + '/' + msg.payload.values[i].id;
node.send({ payload:newmessage, topic:newtopic });
}

return msg;

#################################################################################

result like this;

iotgateway/HSM1.EGD.SPR.SM/DC2000/ODAGUN_FB : msg : Object

object

payload: 24.0999985

topic: "iotgateway/HSM1.EGD.SPR.SM/DC2000/ODAGUN_FB"

_msgid: "4c36ac97.64fa74"


iotgateway/HSM1.EGD.SPR.SM/DC2000/ODAKUZ_FB : msg : Object

object

payload: 21.4999981

topic: "iotgateway/HSM1.EGD.SPR.SM/DC2000/ODAKUZ_FB"

_msgid: "344a4e1b.626562"

Yes, same method, i used a shorthand/ES6 version

You can use something like:
node.send({topic:e.id, payload:e.v})