Filtering data and outputting to Function node with multiple outputs

Hopefully somebody can help me with the following:
I have incoming serial data with needs to be separated via a function node, now i am able to split the sentence to their propiatary ID but i can´t manage to send them to their designated Function node output on the message nr. ID.
The sentence is as follows:
<$GPGSV,8,1,25,21,44,141,47,15,14,049,44,6,31,255,46,3,25,280,4475>
<$GPGSV,8,2,25,18,61,057,48,22,68,320,52,27,34,268,47,24,32,076,45
76>
<$GPGSV,8,3,25,14,51,214,49,19,23,308,467E>
<$GPGSV,8,4,25,51,44,183,49,46,41,169,43,48,36,220,45
47>
<$GLGSV,8,5,25,82,49,219,52,76,22,051,41,83,37,316,51,67,57,010,516C>
<$GLGSV,8,6,25,77,24,108,44,81,10,181,46,78,1,152,34,66,18,060,45
50>
<$GLGSV,8,7,25,68,37,284,505C>
<$GBGSV,8,8,25,111,35,221,47,112,4,179,39,114,48,290,48
11>

Where the number 8 is the total amount of messages and the number 1 till 8 are the message nr.
The number 8 can also excist lower than 8 but the given fact are the message numbers.
Now i am able to split on the talker ID $GPGDV, $GLGSV and $GSGSV so that´s sorted, the only thing i am struggling with is to send the sentences with their message nrs. to a function node output as sentence.
In this case $GPGSV does consist 4 separate message nrs. which needs to be send to their individual output on a function node.
As you can see i do get the 4 sentences (sentence 1 till 4) out on the function node but need to have them all separately. so the sentence with message ID nr. 1 to Function node output 1, sentence with message nr 2 to output 2, sentence with message nr. 3 to output 3 and message nr. 4 to output 4.

Your help with be highly appreciated to help me further into bringing this data into a bargraph.

The switch node is provided to route messages on multiple outputs according to a property of the data.

By default it looks at msg.payload but any property can be used, such as msg.payload.message_nr

To do it in the function after you split the payload you can do.

const output = []; 
const parts = msg.payload.split(",")
output[parts[2]-1]  = {
    payload: {
        message_nr: parts[2]
        //add other items here
    }
}
return output;

P.S When posting code please post as text so others can copy it and do not need to retype it.

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

Got it working by using a Switch node, thanks for the hint, was a little headache but at the end it all worked out for me. PS. sorry for not posting the code inbetween ´´´ was quite late and couldn´t find the right keys to add the code :wink: .

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