Split to different outputs

I am using a split node to tear apart a 8 bit binary number in string with fixed lenght of 1.
Is there a way to split it in different outputs ?
Is it possible to use the switch node outputs with the split node to separate them or add outputs in the split node itself?
Thank you

Indeed it is possible to use the switch node along with the split node exactly like you described. It is just a matter of configuring both nodes accordingly.

You will want to split your string with a fixed length of one.

r-01

Then in your switch node you should create as many outputs as required and create the rules to handle the index of the split messages.

This is how the testing flow looks like (for a binary number of four digits):

2 Likes

Thank you so much Andrei,
The problem is that this only works the first time the number is injected cause the index numbers are incremented in every injection in the split node and they don t show in the outputs anymore.
Is there a way to have always the same index number or any walkaround?
Thank you again.

Hi @dakure,

I share the testing flow below. As a matter of fact the value of msg.parts.index is "restarted" for each incoming payload (in other words for each injection). Let me know if I am missing something so we can clarify or find an alternative solution.

r-04

[{"id":"2202b21f.3f4d7e","type":"tab","label":"Split and switch string","disabled":false,"info":""},{"id":"92e26cbf.d1005","type":"split","z":"2202b21f.3f4d7e","name":"","splt":"1","spltType":"len","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":270,"y":140,"wires":[["7e0b01e6.4fe07"]]},{"id":"b156d544.144f08","type":"inject","z":"2202b21f.3f4d7e","name":"","topic":"","payload":"1001","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":140,"wires":[["92e26cbf.d1005"]]},{"id":"6a2fed9e.1ad054","type":"debug","z":"2202b21f.3f4d7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"parts.index","x":600,"y":100,"wires":[]},{"id":"7e0b01e6.4fe07","type":"switch","z":"2202b21f.3f4d7e","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"},{"t":"eq","v":"3","vt":"num"}],"checkall":"true","repair":false,"outputs":4,"x":410,"y":140,"wires":[["6a2fed9e.1ad054"],["105055c9.5a19ea"],["26c7ab09.eb4054"],["b1e6810f.30e29"]]},{"id":"feba729e.fcdd8","type":"comment","z":"2202b21f.3f4d7e","name":"Split and switch string","info":"Source: https://discourse.nodered.org/t/split-to-different-outputs/5773/2\n","x":140,"y":60,"wires":[]},{"id":"105055c9.5a19ea","type":"debug","z":"2202b21f.3f4d7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"parts.index","x":600,"y":140,"wires":[]},{"id":"26c7ab09.eb4054","type":"debug","z":"2202b21f.3f4d7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"parts.index","x":600,"y":180,"wires":[]},{"id":"b1e6810f.30e29","type":"debug","z":"2202b21f.3f4d7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"parts.index","x":600,"y":220,"wires":[]}]

You are completely right sorry.
My mistake was to check the option "Handle as a stream of messages".
Thank you again :smiley: