Split array into different outputs

3,487 views
Skip to first unread message

Stijn

unread,
Jan 7, 2018, 6:54:59 PM1/7/18
to Node-RED
Hi All,

have a simple problem which I can't figure out for some time now.

trying to split a data array into different values I could use for a system overview.
data is coming from a modbus and is looking like this:


Goal is to split the different arrays into seperate outputs.
output 0 = 303, output 1 = 0,...
how do I configure the splitter and probably necessary switch

Thanks for helping me out!

Stijn



Auto Generated Inline Image 1
Auto Generated Inline Image 2

Colin Law

unread,
Jan 8, 2018, 4:22:40 AM1/8/18
to node...@googlegroups.com
If you need the data on separate outputs then something like this should do the job I think. The key is to move the array in payload.data into the payload so the split can do its job.

[{"id":"50d172ef.c54054","type":"split","z":"f0414dd0.dd514","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":576,"y":384,"wires":[["7818b710.a3c9d"]]},{"id":"43471700.f73f3","type":"inject","z":"f0414dd0.dd514","name":"","topic":"","payload":"{\"data\":[\"a\",\"b\",\"c\"]}","payloadType":"json","repeat":"","crontab":"","once":false,"x":125,"y":384,"wires":[["3b872094.cdb788"]]},{"id":"64ffebce.025e24","type":"debug","z":"f0414dd0.dd514","name":"","active":true,"console":"false","complete":"payload","x":545,"y":463,"wires":[]},{"id":"3b872094.cdb788","type":"change","z":"f0414dd0.dd514","name":"","rules":[{"t":"move","p":"payload.data","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":358,"y":384,"wires":[["50d172ef.c54054"]]},{"id":"7818b710.a3c9d","type":"switch","z":"f0414dd0.dd514","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"}],"checkall":"true","outputs":3,"x":313,"y":480,"wires":[["64ffebce.025e24"],["d6dac108.c76df"],["9c591c8d.624118"]]},{"id":"d6dac108.c76df","type":"debug","z":"f0414dd0.dd514","name":"","active":true,"console":"false","complete":"payload","x":549,"y":508,"wires":[]},{"id":"9c591c8d.624118","type":"debug","z":"f0414dd0.dd514","name":"","active":true,"console":"false","complete":"payload","x":551,"y":550,"wires":[]}]

Colin



Stijn



--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/ffe54474-55c0-4546-b463-fe4176ddae3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

steve rickus

unread,
Jan 8, 2018, 3:43:26 PM1/8/18
to Node-RED
Hi-

The idea of mapping Modbus registers to node-red flows or UI elements has come up several times. Here is a pretty detailed discussion from this mailing list last May...

For my own sanity, I like to split up the incoming register values into either one big object with named fields/values, or even separate msg objects with the register name in the msg.topic and the value in msg.payload. It really just depends upon whether I need to be able to individually manipulate the registers (using one msg for each), or I am just polling for a bunch of readings all at the same time (one object with all values for graphing or insertion into a database).
--
Steve
Reply all
Reply to author
Forward
0 new messages