TCP output problem sending byte over 127

I'm facing a very strange problem! :roll_eyes:
I'm tring to send a string (using the TCP output node) created from an a byte array.
The problem is the following: if I send a byte with a value over 127 I receive an additional byte before of byte in question itself, the value of this byte is fixed and is 192.

Example:
Sending 1,3,2,0,0,184,68, I receive 1,3,2,0,0,194,184,68
Sending 1,3,2,0,0,184,68, I receive 1,3,2,0,0,127,68
Sending 1,3,2,0,0,128,68, I receive 1,3,2,0,0,194,128,68

So... if I send a purely alfanumeric string I will not have any problem, but the problem start when the ASCII value of the byte go over 127.

I tried in many flows and many external TCP server, and also in with a TCP node output and input in the same flow, but the problem still remain.

Please... any help?

This is my flow...

[{"id":"305f50e6.a6323","type":"tcp out","z":"d0c7a4b5.cca688","host":"","port":"9998","beserver":"server","base64":false,"end":false,"name":"","x":700,"y":480,"wires":[]},{"id":"d57339bd.53a3b8","type":"tcp in","z":"d0c7a4b5.cca688","name":"","server":"client","host":"192.168.1.65","port":"9998","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":180,"y":540,"wires":[["f21de5d0.5b05b8"]]},{"id":"adc226f0.b85b98","type":"inject","z":"d0c7a4b5.cca688","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":480,"wires":[["cf4bce43.cb859"]]},{"id":"cf4bce43.cb859","type":"function","z":"d0c7a4b5.cca688","name":"Sample frame","func":"msg.payload = [1,3,2,0,0,184,68];\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":480,"wires":[["5774d858.a32628"]]},{"id":"f21de5d0.5b05b8","type":"debug","z":"d0c7a4b5.cca688","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":710,"y":540,"wires":[]},{"id":"5774d858.a32628","type":"function","z":"d0c7a4b5.cca688","name":"bytearray2str","func":"var frame = msg.payload;\nvar pl = \"\";\nfor (i = 0; i < frame.length; i++) pl += String.fromCharCode(frame[i]);\nmsg.payload = pl;\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":480,"wires":[["305f50e6.a6323"]]},{"id":"dbcd9ed3.139bd","type":"function","z":"d0c7a4b5.cca688","name":"Good frame","func":"msg.payload = [1,3,2,0,0,127,68];\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":440,"wires":[["5774d858.a32628"]]},{"id":"9e2054ad.2355c8","type":"inject","z":"d0c7a4b5.cca688","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":440,"wires":[["dbcd9ed3.139bd"]]}]

By default Strings will be encoded with UTF8 - which indeed does encoding for characters above 128 - you need to create a Buffer instead and send that.
https://nodejs.org/api/buffer.html

1 Like

Many thanks! I ignored the existence of the buffer class.