How Setup For Multiple Port TCP Request

Hi All,

I've made small project SCADA using IP Modem. Now i can connect the IP modem with the my node-red server, and there is no problem. But when I connect with more than 1 IP Modem, for example I want to read 2 IP Modem (port : 1111 & port 2222) with different machine register modbus.

With this connection my SCADA it's works with some noise because I'm using Reply TCP node

[{"id":"11f11255.c2726e","type":"inject","z":"a21129dc.613098","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":true,"onceDelay":0.1,"x":160,"y":140,"wires":[["b48c62b3.79539","9764ebba.5ae878","3db9fc7c.5ea234"]]},{"id":"b48c62b3.79539","type":"function","z":"a21129dc.613098","name":"VSD Address from 3200 qty:10","func":"msg.payload  = Buffer.from('01030C80000AC775', 'hex'); //address for equest Modbus\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":100,"wires":[["b0a5bdef.65ca68"]]},{"id":"9764ebba.5ae878","type":"function","z":"a21129dc.613098","name":"active command 8442 qty:1","func":"msg.payload  = Buffer.from('010320FA0001AFFB', 'hex'); //address for equest Modbus\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":150,"wires":[["b0a5bdef.65ca68"]]},{"id":"3db9fc7c.5ea234","type":"function","z":"a21129dc.613098","name":"Zenith 0 qty:3","func":"msg.payload  = Buffer.from('02030000000305F8', 'hex'); //address for equest Modbus\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":210,"wires":[["b0a5bdef.65ca68"]]},{"id":"6314901e.a285f","type":"tcp in","z":"a21129dc.613098","name":"","server":"server","host":"103.253.113.56","port":"9283","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":200,"y":290,"wires":[["1f3d71d.9bb828e","117abb72.930935"]]},{"id":"117abb72.930935","type":"debug","z":"a21129dc.613098","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":270,"wires":[]},{"id":"b0a5bdef.65ca68","type":"tcp out","z":"a21129dc.613098","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"","x":710,"y":180,"wires":[]}]

My questions is, "how to create single communication TCP Request for each port without one reply TCP. "

Regards,
Rizky

Rizky,

did you happen to find a solution? I have the exact same issue

Hi @PiMo131 ,

Still no solutions until now. All port in my tcp out using one reply tcp.

I found the solution...
The TCP node defines to where to send the reply based on a msg._session.
If you switch the msg._session between the TCP nodes you can route the messages.

quick example:

[{"id":"d0bc5a2b.546308","type":"tcp in","z":"e8870a68.032be8","name":"","server":"server","host":"","port":"10001","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":160,"y":160,"wires":[["cfcc02ac.3b1e7","84f31e7d.3d673","c39e1e57.6ba11"]]},{"id":"cfcc02ac.3b1e7","type":"template","z":"e8870a68.032be8","name":"no msg back","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"","x":470,"y":160,"wires":[["694d2eed.11a69"]]},{"id":"694d2eed.11a69","type":"tcp out","z":"e8870a68.032be8","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"reply: the server will get messaged","x":1000,"y":160,"wires":[]},{"id":"84f31e7d.3d673","type":"function","z":"e8870a68.032be8","name":"forward command","func":"var buf = msg.payload;\nvar string = buf.toString('ascii');\nvar n = string.includes(\"ALIVE\")\n\n//msg.payload = n;\n//return msg;\n\nif (n == false) {\n msg.payload = string;\n return msg;\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":200,"wires":[["1ca443d1.ed4a9c"]]},{"id":"ceb27c2a.df207","type":"tcp in","z":"e8870a68.032be8","name":"","server":"client","host":"10.2.9.101","port":"10002","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":200,"y":360,"wires":[["1acb2fce.bce0c","ac906728.efda48","8b3a6e95.c71a4"]]},{"id":"1acb2fce.bce0c","type":"function","z":"e8870a68.032be8","name":"ACK","func":"var buf = msg.payload;\nvar string = buf.toString('ascii');\n\nmsg.payload = string;\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":360,"wires":[["5643c429.b577ac"]]},{"id":"5643c429.b577ac","type":"function","z":"e8870a68.032be8","name":"","func":"if (msg.payload.length == \"24\") {\n    msg.topic = msg.payload.substr(0,3)\n    msg.payload = msg.payload.substr(0,12)+\"\\r\"+\"\\n\";\nreturn msg;\n    \n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":360,"wires":[["b52c2fc4.ceacd"]]},{"id":"ac906728.efda48","type":"template","z":"e8870a68.032be8","name":"no msg back","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"","x":570,"y":420,"wires":[["51179973.2c87d8"]]},{"id":"51179973.2c87d8","type":"tcp out","z":"e8870a68.032be8","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"reply: the server will get messaged","x":1200,"y":460,"wires":[]},{"id":"1ca443d1.ed4a9c","type":"change","z":"e8870a68.032be8","name":"","rules":[{"t":"set","p":"_session","pt":"msg","to":"session2","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":200,"wires":[["51179973.2c87d8"]]},{"id":"c39e1e57.6ba11","type":"change","z":"e8870a68.032be8","name":"","rules":[{"t":"set","p":"_session","pt":"msg","to":"session1","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":240,"wires":[[]]},{"id":"b52c2fc4.ceacd","type":"change","z":"e8870a68.032be8","name":"session","rules":[{"t":"set","p":"_session","pt":"msg","to":"session1","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":360,"wires":[["694d2eed.11a69"]]},{"id":"8b3a6e95.c71a4","type":"change","z":"e8870a68.032be8","name":"","rules":[{"t":"set","p":"_session","pt":"msg","to":"session2","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":460,"wires":[[]]}]

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