Send message on tcp node

Hello
I have an interconnection project with a system communicating in TCP via port 3005.
I set up a TCP request node with the site's IP address and port 3005. As input I put a null inject for the test.

When I click on inject the tcp node shows connect.
Now I have to send a connection request to the system with the following frame:
23 30 30 30 30 31 34 0F 27 78 FF 01 37 0D

What type of data should I use (string number or other)?

Using a function node connected to the TCP input, the below will send a buffer of bytes

const byteArray = [0x23,0x30,0x30,0x30,0x30,0x31,0x34,0x0F,0x27,0x78,0xFF,0x01,0x37,0x0D]
const dataBuffer = Buffer.from(byteArray)
return {payload:dataBuffer}

You could do this directly in the inject node also, by setting the payload type as buffer, and remove 0x, but as this is hexadecimal - I think it will error if using inject

Hello
Great the 1st solution is the correct one. I have feedback from the server.

On the other hand, it comes back in the raw form. How can I reconstruct the frame to do an analysis?

the cat will have to tell me:
23 30 30 30 30 31 15 0E 27 78 FF 01 01 01 0D
return tcp first message

That will be based on the systems documentation in question.
its a buffer of bytes (like we sent) and its responded with its buffer.

You will need to understand what this buffer contains, in order to make is useable for you.

I do at this point suggest to use the excellent node.

By our very own @Steve-Mcl
This Node will help you label and partition the buffer into a usable object, but ultimately, you need to understand the contents of this buffer, to be able to partition it

For the concordance no worries I have a whole document but for that I have to reformat my frames before.

in my previous example:
23 = # start message
30 30 30 30 31 35 = total message length with 23 and OD included
the rest is as posted
OD = /r end of message

except that I receive a lot of messages at the same time and I have to reconstitute them according to 30 30 30 30 3x 3x how can I do?

  1. setup the TCP to split on 0D so that each communication is an "single packet"
  2. check each packet starts with 23
  3. convert the first part of the message to get the ID or length (or whatever you need)
  4. route the remainder of the buffer to a buffer-parser, setup to interpret for the type of message received on step 3

Thank you how do I cut the buffer as soon as I receive a 0D?

I found the solution to have a single message now I isolated the start 23 the length of the total message (30 30 30 30 30 30) and the command code (340A = 2612 after having reversed the two digits).

size message

how I have to do so that each message is translated according to a concordance table (which I have) I have to analyze each buffer to recover the code and transcribe it.

sorry for the questions but i'm a beginner in TCP and buffer.

FYI json flow

[{"id":"ad0170f0.40b16","type":"tab","label":"ORBILITY","disabled":false,"info":""},{"id":"f0e94466.839b88","type":"tcp request","z":"ad0170f0.40b16","server":"93.177.69.133","port":"3005","out":"sit","splitc":" ","name":"","x":590,"y":80,"wires":[["a7d28b8c.49a728"]]},{"id":"7b2cada6.e99494","type":"inject","z":"ad0170f0.40b16","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":40,"wires":[["cad09232.42b39","9bcc76b.56efc88"]]},{"id":"cad09232.42b39","type":"function","z":"ad0170f0.40b16","name":"#9999","func":"const byteArray = [0x23,0x30,0x30,0x30,0x30,0x31,0x34,0x0F,0x27,0x78,0xFF,0x01,0x37,0x0D]\nconst dataBuffer = Buffer.from(byteArray)\nreturn {payload:dataBuffer}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":40,"wires":[["f0e94466.839b88"]]},{"id":"a7d28b8c.49a728","type":"buffer-parser","z":"ad0170f0.40b16","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"hex","name":"start","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"hex","name":"size","offset":1,"length":6,"offsetbit":0,"scale":"1","mask":""},{"type":"hex","name":"clé","offset":7,"length":2,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":790,"y":80,"wires":[["1b5e44ed.9d79ab"]]},{"id":"1b5e44ed.9d79ab","type":"debug","z":"ad0170f0.40b16","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":970,"y":80,"wires":[]},{"id":"9bcc76b.56efc88","type":"trigger","z":"ad0170f0.40b16","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-20","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":170,"y":120,"wires":[["78f312d4.aa3d2c"]]},{"id":"78f312d4.aa3d2c","type":"function","z":"ad0170f0.40b16","name":"#9997","func":"const byteArray = [0x23,0x30,0x30,0x30,0x30,0x31,0x33,0x0D,0x27,0x78,0xFF,0x01,0x0D]\nconst dataBuffer = Buffer.from(byteArray)\nreturn {payload:dataBuffer}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":120,"wires":[["f0e94466.839b88"]]},{"id":"7c4b1f63.c2143","type":"function","z":"ad0170f0.40b16","name":"#2406","func":"const byteArray = [0x23,0x30,0x30,0x30,0x30,0x31,0x35,0x66,0x09,0x78,0xFF,0x01,0x00,0x00,0x0D]\nconst dataBuffer = Buffer.from(byteArray)\nreturn {payload:dataBuffer}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":220,"wires":[["f0e94466.839b88"]]},{"id":"ce7e4a0b.c58148","type":"inject","z":"ad0170f0.40b16","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":220,"wires":[["7c4b1f63.c2143"]]}]

Don't be! its why the forums are here.

I do suggest (if not already using) use the buffer-parser node, its perfect for these types of environments

1 Like

You need to use something to identify the response and direct it to a specific parser (as I said before)...

eg:

demo flow (import using ctrl-i):

[{"id":"7b2cada6.e99494","type":"inject","z":"ad0170f0.40b16","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":295,"y":160,"wires":[["cad09232.42b39"]],"l":false},{"id":"cad09232.42b39","type":"function","z":"ad0170f0.40b16","name":"#9999","func":"const byteArray = [0x23,0x30,0x30,0x30,0x30,0x31,0x34,0x0F,0x27,0x78,0xFF,0x01,0x37,0x0D]\nconst dataBuffer = Buffer.from(byteArray)\nreturn {payload:dataBuffer}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":160,"wires":[["a7d28b8c.49a728"]]},{"id":"a7d28b8c.49a728","type":"buffer-parser","z":"ad0170f0.40b16","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"hex","name":"start","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"string","name":"size","offset":1,"length":6,"offsetbit":0,"scale":"1","mask":""},{"type":"uint16le","name":"clé","offset":7,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"buffer","name":"data","offset":9,"length":-1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":570,"y":200,"wires":[["212da6fcb2c4e528"]]},{"id":"78f312d4.aa3d2c","type":"function","z":"ad0170f0.40b16","name":"#9997","func":"const byteArray = [0x23,0x30,0x30,0x30,0x30,0x31,0x33,0x0D,0x27,0x78,0xFF,0x01,0x0D]\nconst dataBuffer = Buffer.from(byteArray)\nreturn {payload:dataBuffer}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":200,"wires":[["a7d28b8c.49a728"]]},{"id":"7c4b1f63.c2143","type":"function","z":"ad0170f0.40b16","name":"#2406","func":"const byteArray = [0x23,0x30,0x30,0x30,0x30,0x31,0x35,0x66,0x09,0x78,0xFF,0x01,0x00,0x00,0x0D]\nconst dataBuffer = Buffer.from(byteArray)\nreturn {payload:dataBuffer}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":240,"wires":[["a7d28b8c.49a728"]]},{"id":"ce7e4a0b.c58148","type":"inject","z":"ad0170f0.40b16","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":295,"y":240,"wires":[["7c4b1f63.c2143"]],"l":false},{"id":"aab0085b86ba368a","type":"inject","z":"ad0170f0.40b16","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":295,"y":200,"wires":[["78f312d4.aa3d2c"]],"l":false},{"id":"2db36df574901360","type":"switch","z":"ad0170f0.40b16","name":"9999 \\n 9997 \\n 2406 \\n other","property":"payload[\"clé\"]","propertyType":"msg","rules":[{"t":"eq","v":"9999","vt":"num"},{"t":"eq","v":"9997","vt":"num"},{"t":"eq","v":"2406","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":770,"y":200,"wires":[["d6c58a522011f202"],["53e4663efcab6397"],["9b619c4c55f3504e"],[]]},{"id":"d6c58a522011f202","type":"buffer-parser","z":"ad0170f0.40b16","name":"parse 9999 type","data":"payload.data","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint16le","name":"num1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint16le","name":"num2","offset":2,"length":1,"offsetbit":0,"scale":"/ 100","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload.parsed","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":960,"y":160,"wires":[["1b5e44ed.9d79ab"]]},{"id":"53e4663efcab6397","type":"buffer-parser","z":"ad0170f0.40b16","name":"parse 9997 type","data":"payload.data","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint16le","name":"num1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint16le","name":"num2","offset":2,"length":1,"offsetbit":0,"scale":"/ 100","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload.parsed","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":960,"y":200,"wires":[["32044cf957826b16"]]},{"id":"9b619c4c55f3504e","type":"buffer-parser","z":"ad0170f0.40b16","name":"parse 2406 type","data":"payload.data","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint16le","name":"num1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint16le","name":"num2","offset":2,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"byte","name":"byte","offset":4,"length":1,"offsetbit":0,"scale":"/ 100","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload.parsed","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":960,"y":240,"wires":[["fec8ce59c151dea9"]]},{"id":"212da6fcb2c4e528","type":"function","z":"ad0170f0.40b16","name":"Size Str to Number","func":"msg.payload.size = Number(msg.payload.size)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":685,"y":200,"wires":[["2db36df574901360"]],"icon":"node-red-dashboard/ui_numeric.png","l":false}]

I had done a similar thing but I do not go back through a parse node.

what is node 123?

Just a function node

Hi,

I have made good progress on the subject but I still have two points that I cannot resolve.

  • I receive a payload with an event in HEXA on 2 bits "002b" which must be transcribed into numeric (without inversion of the HEXA bits) to have the value "43"
  • On the second part of the capture we see that the buffer does [819], which makes me understand, that it cut the messages badly. how can i resolve this?

Use uint16 instead of int16.

INT16 is "16 bit Integer" (e.g. -32768 ~ 32767)
UINT16 is "Unsigned 16 bit Integer" (e.g. 0 ~ 65535)

e.g.:

I configured my node buffer-parser in unit16(le) but the result is 0018 and is not converted

You have not set that one to uint. it is set to "hex" which is shorthand for "hexadecimal string" (e.g. 0x0018 === 24 decimal)

can the tcp node be configured by msg? I would like to make a msg.url and msp.port in the same style as that of Http with msg.url

Yes if you read the help text it can.

Thank you