Subroutine Missing return node information

I have this subroutine which I am calling with a link call node:

I am always getting "Missing return node information", due to the split function, which contains:

msg.payload.split("##").forEach(e => { 
    if (!e) {return;}
    node.send({ payload: e + "##"}) 
    
});

Any way to let it work?

Dont throw away the original message. It contains the routing info for the subroutine to return to.

But - you might have a different issue here - splitting will generate multiple responses. A link return should only be triggered once per call.

My suggestion is to do the splitting OUTSIDE of the subroutine.

Or, only return a single msg (the original msg object, complete with its original ._link property) after everything is done.

maybe you should explain in words what overall goal is?

EDIT

Do you really need to send individual messages?

It would likely be better to process the split lines into an array in payload then use the split node AFTER the link-call

I'm afraid I can't do it outside as I need this in 240 different nodes in my project. The input in the function is a long string of messages separated by "##", which I should need to split. (i.e: *#*1##*#*1##*#18*74#0*113*0##*#*1##)

What I need to do is to discard all parts like this: *#*1## and keep the valid message.

This doesnt make a whole lot of sense to me.

are you expecting 1 or multiple messages to be sent back from the subroutine?

can you share:

  • 1 or 2 sample data (that the exec would send)
  • this subroutine so I can see what it is doing
  • what the message(s) should liike like AFTER the processing of this subroutine

That's not easy, as this is a OWN bus (Legrand) and you can't replicate on your own.
But take that message: *#*1##*#*1##*#18*74#0*113*0##*#*1##
I don't need to extract ALL of the messages, but just *#18*74#0*113*0##, discarding the rest. But this central message can vary, depending on the input in the subroutine.

I dont need anything other than 1 or 2 example (input) data strings, a copy of this subroutine and your answers to "what the message(s) should liike like AFTER the processing of this subroutine?" and "are you expecting 1 or multiple messages to be sent back from the subroutine?"

Currently I am doing this in a subflow (which is working) but I'd like to move it into a subroutine

And i can help you if you answer the questions and select + export the 8 nodes in this picture:
image

flows.json (4.3 KB)
Attached

This is another message out of the exec: *#*1##*#*1##*#18*5158*113*490##*#*1##

for future reference, please just paste the JSON into a code block.

ok you still haven't answered the questions. Let me phrase this a different way.

Suppose the subroutine was triggered and the response from the EXEC was *#*1##*#*1##*#18*74#0*113*0##*#*1##:

  • how many messages would you expect to be outputted from your function nodes?
  • what would they contain?

Yes, I answered here
Anyway, I just need *#18*74#0*113*0## discarding the rest. One message.

One more thing: pls discard the function in "COnverte e filtra output". It is not needed

I assume the values change so what defines the part of interest?

e.g. will it always be *#*1##*#*1##[xxxxxxxxxxx]*#*1## where xxxxxxxxxxx is the interesting part?

is there a document that states the structure of this data?

YES, as I said the content can change, but the part of interest is always that one, discarding all *#*1##. parts

Your OG split should work fine , as Steve said, send the OG msg , do not construct a new message.
This should work also

msg.payload = msg.payload.split("*#*1##").find((str) => str);
return msg;
1 Like

does this look right?

it looks very much right!

Try this then.

you will need to remove the "fake data" node and check that the output of the EXEC maintains the msg.linksource property for it to work in production.

[{"id":"f4fddf75fcab76bd","type":"inject","z":"eaa6d97a6ede80ab","name":"*#*1##*#*1##*#18*5158*113*490##*#*1##","props":[{"p":"data","v":"*#*1##*#*1##*#18*5158*113*490##*#*1##","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":1060,"y":2780,"wires":[["651dee8c58c1df85"]]},{"id":"dd4dba7aa1c70279","type":"inject","z":"eaa6d97a6ede80ab","name":"*#*1##*#*1##*#18*74#0*113*0##*#*1##","props":[{"p":"data","v":"*#*1##*#*1##*#18*74#0*113*0##*#*1##","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":1070,"y":2820,"wires":[["651dee8c58c1df85"]]},{"id":"38eb990e6db1dcc8","type":"inject","z":"eaa6d97a6ede80ab","name":"*bad-data*#18*5158*113*490*bad-data*","props":[{"p":"data","v":"*bad-data*#18*5158*113*490*bad-data*","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":1070,"y":2860,"wires":[["651dee8c58c1df85"]]},{"id":"651dee8c58c1df85","type":"link call","z":"eaa6d97a6ede80ab","name":"","links":["8b9393b8466fa7c0"],"linkType":"static","timeout":"30","x":1410,"y":2820,"wires":[["12de24bc0b74b5c3"]]},{"id":"12de24bc0b74b5c3","type":"debug","z":"eaa6d97a6ede80ab","name":"debug 128","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1470,"y":2880,"wires":[]},{"id":"01ad3b3ec8cc86aa","type":"group","z":"eaa6d97a6ede80ab","name":"ComandoGenericoOWN","style":{"label":true},"nodes":["c949ccec8874aa3f","ff31eb43d0d56564","8b9393b8466fa7c0","e43ce6325fd32295","9bc58c33413af99e","c34f56c232187db3","eb5f4a08de054e18","29886815c09103ca"],"x":904,"y":2929,"w":662,"h":212},{"id":"c949ccec8874aa3f","type":"exec","z":"eaa6d97a6ede80ab","d":true,"g":"01ad3b3ec8cc86aa","command":"/home/boss/.node-red/assets/send_SCS2.py","addpay":"payload","append":"","useSpawn":"true","timer":"","winHide":false,"oldrc":false,"name":"send_SCS2.py","x":1100,"y":3040,"wires":[["ff31eb43d0d56564"],[],[]]},{"id":"ff31eb43d0d56564","type":"function","z":"eaa6d97a6ede80ab","g":"01ad3b3ec8cc86aa","name":"grab data part (or throw)","func":"\n// for downstream debugging when errors occur\nmsg._originalData = msg.payload\n\n// v1 is it is ALWAYS xxxx then simply split on that!\nconst star_hash_check = msg.payload.indexOf('*#*1##') > -1\nif (star_hash_check) {\n    const result = msg.payload.split('*#*1##').filter(e => !!e)\n    if (result.length) {\n        msg.payload = result[0]\n        return msg\n    }\n}\n// if we reach here, then data not found, throw error\nmsg.payload = null\nnode.error(\"not found\", msg);\n\n\n// ---- alt ---- //\n// v2 - using regex with a capturing group\n// const result = /(?:\\*\\#\\*\\d+\\#\\#)+(.*)(?:\\*\\#\\*\\d+\\#\\#)+/.exec(msg.payload)\n// if (result.length > 1) {\n//     msg.payload = result[1]\n//     return msg\n// }\n\n\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1410,"y":3020,"wires":[["9bc58c33413af99e"]]},{"id":"8b9393b8466fa7c0","type":"link in","z":"eaa6d97a6ede80ab","g":"01ad3b3ec8cc86aa","name":"ComandoGenericoOWN","links":[],"x":945,"y":2970,"wires":[["c34f56c232187db3"]]},{"id":"e43ce6325fd32295","type":"function","z":"eaa6d97a6ede80ab","g":"01ad3b3ec8cc86aa","name":"","func":"// Se arriva un msg.options, \n// ha la prioritĂ  sull'impostazione di msg.payload\n\n\nif (msg.options) {\n    msg.payload = msg.options;\n}\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1200,"y":2970,"wires":[["c949ccec8874aa3f","29886815c09103ca"]]},{"id":"9bc58c33413af99e","type":"link out","z":"eaa6d97a6ede80ab","g":"01ad3b3ec8cc86aa","name":"link out 4","mode":"return","links":[],"x":1525,"y":3080,"wires":[]},{"id":"c34f56c232187db3","type":"delay","z":"eaa6d97a6ede80ab","g":"01ad3b3ec8cc86aa","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"0.1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1050,"y":2970,"wires":[["e43ce6325fd32295"]]},{"id":"eb5f4a08de054e18","type":"catch","z":"eaa6d97a6ede80ab","g":"01ad3b3ec8cc86aa","name":"","scope":"group","uncaught":false,"x":1360,"y":3080,"wires":[["9bc58c33413af99e"]]},{"id":"29886815c09103ca","type":"change","z":"eaa6d97a6ede80ab","g":"01ad3b3ec8cc86aa","name":"fake data","rules":[{"t":"move","p":"data","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":3100,"wires":[["ff31eb43d0d56564"]]}]
1 Like