Extract many value from a string in different msg.payload

Hi all
I'm a newbie in node red, but I like this powerful tool.
I'm extracting a topic from MQTT with a lot of data with single message and I need to take every row value and create a msg.paylod for each value.
So, I was thinking to a function node, or a json, to prepare the message to be split in various node message.

This is the mqtt list from this topic, ho can I use a specific msg for each data?

If i understand correctly.
This will take the last part of topic and create a msg.payload.<topic_last_value>.
I would suggest not using spaces in topic paths, best to use _, as the spaces in property names will cause issues later on.

[{"id":"b377b8bf3c14e88e","type":"inject","z":"058fb5958f470e48","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"my/topic/paath/sting_mode","payload":"test","payloadType":"str","x":210,"y":100,"wires":[["f9d571f2c3aed726"]]},{"id":"f9d571f2c3aed726","type":"function","z":"058fb5958f470e48","name":"function 15","func":"const property_name = msg.topic.split(\"/\").slice(-1)[0];\nmsg.payload = {[property_name]: msg.payload};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":100,"wires":[["2be82c233353dfa2"]]},{"id":"2be82c233353dfa2","type":"debug","z":"058fb5958f470e48","name":"debug 102","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":180,"wires":[]}]

Payload output


p.s. It is best to supply data in a copyable form, the debug node offers a way to copy values, hover you mouse to side of property name and a copy value icon will appear.

It might be easier to have multiple MQTT In nodes, one for each topic. So one for espaltherma/OneATTR/Powerful DHW Operation ON/OFF, one for espaltherma/OneATTR/Circulation pump operation and so on. It does depend on what you want to do with the messages though.

Those are very odd MQTT topics though. If you have control over them then I suggest simplifying, and in particular taking out spaces. The spaces just make life difficult.

Do you think multiple MQTT increase load of work for system?

Not significantly. Not unless you have thousands of messages a second.
Always use the KISS principle. Use the simplest solution you can think of and only complicate it if you find the simple solution has a problem. The bottlenecks in your system will virtually always not be where you expect them to be so it is not good practice to complicate the solution for what you think may be performance benefits.

Even though you have multiple MQTT Input nodes, you will only have one MQTT Server node, that all the Input nodes use, so there is still only one comms connection to the broker.

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