UDP communication error

I am new here. I am running Node-Red on a Rapsberry Pi 4B and want to control a PLC with it. The PLC communicates with short binary messages over UDP, but does not respond to messages sent by Node-Red. I checked the data sent by Node-Red with Wireshark and I see a data error: every data larger than 0x7F is preceded by a 0xC2 or 0xC3 byte. I could not believe my eyes! How is it possible?
I can control this PLC well with PHP/Javascript programs.
The PLC is at a local address (192.168.xxx.xxx), but the same phenomenon occurs when I test Node-Red at 127.0.0.1. Ping also works in Node-Red.

Can somebody help me? Thanks in advance.

Share a flow and sample data. Tbh, it's likely something you are doing but unless you share more it is impossible to tell.

[{"id":"f7a39507287dac0f","type":"ui_button","z":"8c312104f03a1669","name":"","group":"5ecce8e816abc178","order":1,"width":"2","height":"1","passthru":false,"label":"Spot","tooltip":"","color":"optional text/icon color","bgcolor":"optional background color","className":"","icon":"","payload":"48","payloadType":"num","topic":"topic","topicType":"msg","x":530,"y":340,"wires":[["4758aa16e95ac4f6"]]},{"id":"2daeafc2fe983421","type":"udp in","z":"8c312104f03a1669","name":"PLC Receiver","iface":"","port":"1881","ipv":"udp4","multicast":"false","group":"","datatype":"utf8","x":110,"y":380,"wires":[["c861755ddd885fd4","95f51235a4dc1fb3"]]},{"id":"12900f480bd8b948","type":"function","z":"8c312104f03a1669","name":"Set","func":"var send = new Array();\nsend = [129,8,0,0,126,37,0,0,0,6];\nvar cs = send.reduce((pv, cv) => pv + cv, 0);\nsend.push(cs % 256);\nsend.splice(0,0,170,85);\nmsg.payload = \"\";\nfor (let i in send) msg.payload = msg.payload.concat(String.fromCharCode(send[i]));\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":160,"wires":[["b3d74fe5470785b0","20f1909ea25d5b27"]]},{"id":"20f1909ea25d5b27","type":"udp out","z":"8c312104f03a1669","name":"","addr":"127.0.0.1","iface":"","port":"1881","ipv":"udp4","outport":"","base64":false,"multicast":"false","x":950,"y":380,"wires":[]},{"id":"c861755ddd885fd4","type":"debug","z":"8c312104f03a1669","name":"A","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":170,"y":160,"wires":[]},{"id":"7c21d9d58920be29","type":"debug","z":"8c312104f03a1669","name":"B","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":350,"y":160,"wires":[]},{"id":"b3d74fe5470785b0","type":"debug","z":"8c312104f03a1669","name":"C","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":160,"wires":[]},{"id":"fcefa3d211ac4742","type":"inject","z":"8c312104f03a1669","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":540,"y":160,"wires":[["12900f480bd8b948"]]},{"id":"95f51235a4dc1fb3","type":"function","z":"8c312104f03a1669","name":"Receive","func":"var rec = new Array;\nvar fault = \"\";\nfor (let i=0; i<msg.payload.length; i++) rec[i] = msg.payload.charCodeAt(i);\nif ((rec[0] == 170) && (rec[1] == 85)) {\n    rec.splice(0,2);\n    var rcs = rec.pop();\n    var pcs = rec.reduce((pv, cv) => pv + cv, 0);\n    if (rcs != (pcs % 256)) fault = \"CS hiba!\";\n}\nelse fault = \"Átviteli hiba!\";\nif (fault == \"\") msg.payload = rec.toString();\nelse msg.payload = fault;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":380,"wires":[["7c21d9d58920be29"]]},{"id":"4758aa16e95ac4f6","type":"function","z":"8c312104f03a1669","name":"On/Off","func":"var send = new Array();\nsend = [250,240,130,9,0,0,127,0,0,0,0,1,msg.payload];\nvar cs = send.reduce((pv, cv) => pv + cv, 0);\nsend.push(cs % 256);\nsend.splice(0,0,170,85);\nmsg.payload = \"\";\nfor (let i in send) msg.payload = msg.payload.concat(String.fromCharCode(send[i]));\nmsg.topic = msg.payload.length;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":380,"wires":[["20f1909ea25d5b27","b3d74fe5470785b0"]]},{"id":"ac47f2d5240c0b3f","type":"ui_button","z":"8c312104f03a1669","name":"","group":"5ecce8e816abc178","order":1,"width":"2","height":"1","passthru":false,"label":"Nappali","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"22","payloadType":"num","topic":"topic","topicType":"msg","x":540,"y":220,"wires":[["4758aa16e95ac4f6"]]},{"id":"ea51b2ef270caae3","type":"ui_button","z":"8c312104f03a1669","name":"","group":"5ecce8e816abc178","order":2,"width":"2","height":"1","passthru":false,"label":"Olvasó","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"21","payloadType":"num","topic":"topic","topicType":"msg","x":540,"y":260,"wires":[["4758aa16e95ac4f6"]]},{"id":"43e9bf3ef12b83b5","type":"ui_button","z":"8c312104f03a1669","name":"","group":"5ecce8e816abc178","order":3,"width":"2","height":"1","passthru":false,"label":"Dolgozó","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"25","payloadType":"num","topic":"topic","topicType":"msg","x":540,"y":300,"wires":[["4758aa16e95ac4f6"]]},{"id":"f7a2dcb1c26f5902","type":"ui_button","z":"8c312104f03a1669","name":"","group":"5ecce8e816abc178","order":4,"width":"2","height":"1","passthru":false,"label":"Oldalfal","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"30","payloadType":"num","topic":"topic","topicType":"msg","x":540,"y":380,"wires":[["4758aa16e95ac4f6"]]},{"id":"501f59028a9ac1d9","type":"ui_button","z":"8c312104f03a1669","name":"","group":"5ecce8e816abc178","order":5,"width":"2","height":"1","passthru":false,"label":"Sólámpa","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"29","payloadType":"num","topic":"topic","topicType":"msg","x":540,"y":420,"wires":[["4758aa16e95ac4f6"]]},{"id":"cee7ba676f8d487a","type":"ui_button","z":"8c312104f03a1669","name":"","group":"5ecce8e816abc178","order":6,"width":"2","height":"1","passthru":false,"label":"Előtér","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"27","payloadType":"num","topic":"topic","topicType":"msg","x":530,"y":460,"wires":[["4758aa16e95ac4f6"]]},{"id":"7fa589bdcb15bc03","type":"ui_button","z":"8c312104f03a1669","name":"","group":"5ecce8e816abc178","order":7,"width":"2","height":"1","passthru":false,"label":"Irányfény","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"28","payloadType":"num","topic":"topic","topicType":"msg","x":540,"y":500,"wires":[["4758aa16e95ac4f6"]]},{"id":"afcde364ca5e12e1","type":"ui_button","z":"8c312104f03a1669","name":"","group":"5ecce8e816abc178","order":8,"width":"2","height":"1","passthru":false,"label":"Étkező","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"24","payloadType":"num","topic":"topic","topicType":"msg","x":530,"y":540,"wires":[["4758aa16e95ac4f6"]]},{"id":"5ecce8e816abc178","type":"ui_group","name":"Emelet","tab":"37b5116cd2af04e9","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"37b5116cd2af04e9","type":"ui_tab","name":"Világítás","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Admin Edit: surround code in code block!

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

Also, what is the PLC make and model

And lastly, what are you seeing in wireshark and what SHOULD it be

Try this...

[{"id":"2daeafc2fe983421","type":"udp in","z":"8fb7704d922a7884","name":"PLC Receiver","iface":"","port":"1889","ipv":"udp4","multicast":"false","group":"","datatype":"buffer","x":130,"y":1200,"wires":[["c861755ddd885fd4","95f51235a4dc1fb3"]]},{"id":"12900f480bd8b948","type":"function","z":"8fb7704d922a7884","name":"Set","func":"const data = [129, 8, 0, 0, 126, 37, 0, 0, 0, 6];\nconst cs = data.reduce((pv, cv) => pv + cv, 0);\ndata.push(cs % 256);\ndata.unshift(170, 85);\nmsg.payload = Buffer.from(data)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":770,"y":1080,"wires":[["b3d74fe5470785b0","20f1909ea25d5b27"]]},{"id":"20f1909ea25d5b27","type":"udp out","z":"8fb7704d922a7884","name":"","addr":"127.0.0.1","iface":"","port":"1889","ipv":"udp4","outport":"","base64":false,"multicast":"false","x":970,"y":1200,"wires":[]},{"id":"c861755ddd885fd4","type":"debug","z":"8fb7704d922a7884","name":"A","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":210,"y":1080,"wires":[]},{"id":"7c21d9d58920be29","type":"debug","z":"8fb7704d922a7884","name":"B","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":1080,"wires":[]},{"id":"b3d74fe5470785b0","type":"debug","z":"8fb7704d922a7884","name":"C","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":950,"y":1080,"wires":[]},{"id":"fcefa3d211ac4742","type":"inject","z":"8fb7704d922a7884","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":600,"y":1080,"wires":[["12900f480bd8b948"]]},{"id":"95f51235a4dc1fb3","type":"function","z":"8fb7704d922a7884","name":"Receive","func":"/** @type {Buffer} */\nconst data = msg.payload;\nlet fault = \"\";\nmsg.payload = {}\n\nif ((data[0] == 170) && (data[1] == 85)) {\n    const innerData = data.subarray(2, -1);\n    const rcs = data[data.length - 1];\n    const pcs = innerData.reduce((pv, cv) => pv + cv, 0);\n    if (rcs != (pcs % 256)) fault = \"CS hiba!\";\n} else {\n    fault = \"Átviteli hiba!\";\n}\n\nif (fault == \"\") {\n    msg.payload = {\n        data,\n        dataAsString: data.toString()\n    }\n} else {\n    msg.fault = fault;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":1200,"wires":[["7c21d9d58920be29"]]},{"id":"4758aa16e95ac4f6","type":"function","z":"8fb7704d922a7884","name":"On/Off","func":"const arr = [250, 240, 130, 9, 0, 0, 127, 0, 0, 0, 0, 1, msg.payload];\nconst cs = arr.reduce((pv, cv) => pv + cv, 0);\narr.push(cs % 256);\narr.unshift(170, 85);\nmsg.payload = Buffer.from(arr);\nmsg.topic = msg.payload.length;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":1200,"wires":[["20f1909ea25d5b27","b3d74fe5470785b0"]]},{"id":"bf8523505ddbddba","type":"inject","z":"8fb7704d922a7884","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":590,"y":1160,"wires":[["4758aa16e95ac4f6"]]},{"id":"b0468be3ca3d3ab9","type":"inject","z":"8fb7704d922a7884","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"22","payloadType":"num","x":590,"y":1200,"wires":[["4758aa16e95ac4f6"]]},{"id":"d441d6372a12f5d7","type":"inject","z":"8fb7704d922a7884","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"23","payloadType":"num","x":590,"y":1240,"wires":[["4758aa16e95ac4f6"]]}]

NOTES...
I am unsure why you were declaring bytes in an array then using fromCharCode - maybe I misunderstand your requirement (you didnt post any protocol details so i am guessing)

Anyhow, this all works if you stick to Buffers

I think the c2 etc will be coming from the way utf8 strings get converted to binary. As Steve says you need to declare the payload as a raw binary buffer.

Thanks for the help, it works great!

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