Sending response back to the right serial port

I have a solution with 2 serial inputs and 1 serial output, where a response is received on the output for a received message.
If data comes from both inputs, how can I ensure that I send a response back to the input it came from.

Serialports are can only be connected to one physical port - so the response will go to whichever the the output port is set as.

Do you have the clients transmitting to different input ports on the node red device. But both listening to the same output port? If so you will have to make sure that the data itself contains information that allows the clients to work out who the response is for.

@dceejay @Colin

I have made this demo flow that came to me, my brain just had to reset! :wink: still trying to learn NR.

Remember - just an example, maybe this can help others.

Normally closed, only opens output if the associated input has received something, this is to ensure that the other output does not send anything out
This setup has a primary and a secondary channel, there are 2 servers that replicate data between each other, so if the primary is down, then the secondary is used. In rare cases where servers cannot see each other, it can happen that it sends on both to be safe, I have inserted a delay on the secondary channel to make sure job is not running at the same time.

[{"id":"265a309e98b5a1b6","type":"gate","z":"0ea2c1ce9b217757","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"storeInFile","x":830,"y":420,"wires":[["b9bf9b79908d75b3","a9d183090a09981a"]]},{"id":"ed61b502aeedd2da","type":"change","z":"0ea2c1ce9b217757","name":"Open gate","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":420,"wires":[["265a309e98b5a1b6"]]},{"id":"b5c440c4bf192efa","type":"function","z":"0ea2c1ce9b217757","name":"Do something","func":"\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":420,"wires":[["ed61b502aeedd2da","07427541fee95240"]]},{"id":"69de1a2191d7768c","type":"serial in","z":"0ea2c1ce9b217757","name":"","serial":"e907b486fcdc0c6c","x":270,"y":420,"wires":[["b5c440c4bf192efa"]]},{"id":"b9bf9b79908d75b3","type":"serial out","z":"0ea2c1ce9b217757","name":"","serial":"e907b486fcdc0c6c","x":990,"y":420,"wires":[]},{"id":"07427541fee95240","type":"serial out","z":"0ea2c1ce9b217757","name":"","serial":"fe574cc910a03d13","x":510,"y":320,"wires":[]},{"id":"500a44dc5cd4d640","type":"serial in","z":"0ea2c1ce9b217757","name":"","serial":"fe574cc910a03d13","x":630,"y":320,"wires":[["c3698ab656e3dd36","265a309e98b5a1b6","21c125450b806b4d"]]},{"id":"8df74e69a419d5e3","type":"change","z":"0ea2c1ce9b217757","name":"Close gate after 5 sec.","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":320,"wires":[["265a309e98b5a1b6","21c125450b806b4d"]]},{"id":"c3698ab656e3dd36","type":"delay","z":"0ea2c1ce9b217757","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":860,"y":320,"wires":[["8df74e69a419d5e3"]]},{"id":"21c125450b806b4d","type":"gate","z":"0ea2c1ce9b217757","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"storeInFile","x":830,"y":540,"wires":[["c09919c589d9b481","62e9c78b49d00ab9"]]},{"id":"a93ea849f9eff33e","type":"change","z":"0ea2c1ce9b217757","name":"Open gate","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":540,"wires":[["21c125450b806b4d"]]},{"id":"2ced3d90dc648cf4","type":"function","z":"0ea2c1ce9b217757","name":"Do something","func":"\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":540,"wires":[["a93ea849f9eff33e","07427541fee95240"]]},{"id":"1757ba1d7f540ae5","type":"serial in","z":"0ea2c1ce9b217757","name":"","serial":"3b65b70b7316d25f","x":90,"y":540,"wires":[["d2e8e9e1c7021964"]]},{"id":"c09919c589d9b481","type":"serial out","z":"0ea2c1ce9b217757","name":"","serial":"3b65b70b7316d25f","x":990,"y":540,"wires":[]},{"id":"d2e8e9e1c7021964","type":"delay","z":"0ea2c1ce9b217757","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":260,"y":540,"wires":[["2ced3d90dc648cf4"]]},{"id":"e7d1b091ec893ffe","type":"comment","z":"0ea2c1ce9b217757","name":"Primary","info":"","x":170,"y":340,"wires":[]},{"id":"3a1a110f644fbb17","type":"comment","z":"0ea2c1ce9b217757","name":"Secundary","info":"","x":180,"y":480,"wires":[]},{"id":"a9d183090a09981a","type":"debug","z":"0ea2c1ce9b217757","name":"Out Com2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1010,"y":480,"wires":[]},{"id":"62e9c78b49d00ab9","type":"debug","z":"0ea2c1ce9b217757","name":"Out Com4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1010,"y":600,"wires":[]},{"id":"e907b486fcdc0c6c","type":"serial-port","name":"","serialport":"COM2","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"500","bin":"false","out":"interbyte","addchar":"","responsetimeout":"10000"},{"id":"fe574cc910a03d13","type":"serial-port","name":"","serialport":"COM9","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"},{"id":"3b65b70b7316d25f","type":"serial-port","name":"","serialport":"COM4","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"500","bin":"false","out":"interbyte","addchar":"","responsetimeout":"10000"}]

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