Yet another "strange" behavior of the switch node

First of all, some contextual info
OS: Linux RevPi34798 4.19.95-rt38-v7.
Dashboard version: v1.35.

The problem. I am designing a flow where a given message payload of the form

{
"section_1":{"CEV" : 0, "s" : 2},
"section_2":{"CEV" : 1, "s" : 3},
"section_n":{"CEV" : 0, "s" : 1}
}

(n stands for a generic number of sections, and can be just 1) is first split with a standard (dashboard) split node in parts whose msg.payload have the following form:

{"CEV":0, "s":2}

These parts are then split again in messages whose payload are their simple numerical values: here it comes the problem. I want to route these values by using a switch node according to their msg.part.key value (respectively CEV and s): however, this does not work.
For example, in the 1-section model flow below


where the inject node sec_sts injects the following complete message (copied from the preceding switch node in the full flow)

{
"_msgid":"bd05ad6a.fcb66",
"payload":{"CEV":0,"s":2},
"topic":"section_1",
"_event":"node:d7590ba5.b163f8",
"parts": {
         "id":"7e6805a9.7a7c4c",
         "type":"object",
         "key":"section_1",
         "index":0,
         "count":1}
}

and the split node works perfectly giving the following two complete messages

{
"payload":0,
"topic":"section_1",
"_event":"node:d7590ba5.b163f8",
"parts":{
        "parts":{
                 "id":"7e6805a9.7a7c4c",
                 "type":"object",
                 "key":"section_1",
                 "index":0,
                 "count":1
                 },
        "id":"6cb0f9b3.45c048",
        "type":"object",
        "key":"CEV",
        "index":0,
        "count":2
        },
"_msgid":"8dd99f88.82b48"
}

and

{
"payload":2,
"topic":"section_1",
"_event":"node:d7590ba5.b163f8",
"parts":{
        "parts":{
                "id":"7e6805a9.7a7c4c",
                "type":"object",
                "key":"section_1",
                "index":0,"count":1
                },
        "id":"6cb0f9b3.45c048",
        "type":"object",
        "key":"s",
        "index":1,
        "count":2
        },
"_msgid":"3e32f1bf.799b2e"
}

I am not able to make the sts_router split node work correctly, i.e. to make it work according to the values of the msg.parts.key property. Setting of the sts_router node is


I'm almost sure that I am missing something trivial, but I am not able to see it, so I've decided to ask for your precious help. Thanks in advance.

Can you share this flow?

1 Like

It seems to work for me:

[{"id":"985a0f35b471ede0","type":"inject","z":"b5d64c1e024cd3e1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":80,"wires":[["11070a651fa11b17"]]},{"id":"11070a651fa11b17","type":"function","z":"b5d64c1e024cd3e1","name":"","func":"msg = {\n    \"_msgid\": \"bd05ad6a.fcb66\",\n    \"payload\": { \"CEV\": 0, \"s\": 2 },\n    \"topic\": \"section_1\",\n    \"_event\": \"node:d7590ba5.b163f8\",\n    \"parts\": {\n        \"id\": \"7e6805a9.7a7c4c\",\n        \"type\": \"object\",\n        \"key\": \"section_1\",\n        \"index\": 0,\n        \"count\": 1\n    }\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":240,"y":80,"wires":[["5aa06001df5f592f","1337022978ff3031"]]},{"id":"5aa06001df5f592f","type":"split","z":"b5d64c1e024cd3e1","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":390,"y":80,"wires":[["dd5fe6d32c4004aa","789e98ce129cb03b"]]},{"id":"1337022978ff3031","type":"debug","z":"b5d64c1e024cd3e1","name":"injected data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":370,"y":140,"wires":[]},{"id":"dd5fe6d32c4004aa","type":"switch","z":"b5d64c1e024cd3e1","name":"","property":"parts.key","propertyType":"msg","rules":[{"t":"eq","v":"s","vt":"str"},{"t":"eq","v":"CEV","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":570,"y":80,"wires":[["5f3ddd60801eed9d"],["27bd395092ec0d30"],["a9766439d28fd31e"]]},{"id":"5f3ddd60801eed9d","type":"debug","z":"b5d64c1e024cd3e1","name":"key = s","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":40,"wires":[]},{"id":"27bd395092ec0d30","type":"debug","z":"b5d64c1e024cd3e1","name":"key = CEV","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":80,"wires":[]},{"id":"a9766439d28fd31e","type":"debug","z":"b5d64c1e024cd3e1","name":"otherwise","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":140,"wires":[]},{"id":"789e98ce129cb03b","type":"debug","z":"b5d64c1e024cd3e1","name":"split data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":140,"wires":[]}]
1 Like

Shouldn’t you be testing msg.parts.parts.key?

1 Like

Sure, here it is.
flows-3.json (4.0 KB)

I dont see any issue other than you had turned off the debug node output. Here is your flow with separate debug nodes and output and status enabled....

1 Like

No, I need to access the outer msg.parts.key which correspond to the latest split. Testing msg.parts.parts would be equivalent to extract the value of section_x, which is the same for CEV and s.

You're right: it seems it is an issue of the RIC out node: opening it seem that I lose the graphical enable command, possibly during some edit. I've deleted and readded it, and now it works. Thank you very much

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