Relpy to TCP -- Trouble responding with a "1"

I am trying to setup a simple flow, but having some issues and can't seem to find enough documentation.

I have a device that sends TCP data to my Node Red flow. Immediately after I receive the data, I need to respond with a number 1.


My function is as follows:

msg = 1
return msg;

Any thoughts on how to get Node Red to respond with the number 1 after data is received?

msg.payload = 1;

1 Like

Thank you... If I needed to send the reply in binary, would it just be a simple as:

msg.payload = 0x01;
return msg;

Specifically, here is what I am trying to accomplish:

First, when the module connects to the server, the module sends its IMEI. First comes a short identifying the number of bytes written and then goes IMEI as text (bytes).
For example, IMEI 356307042441013 would be sent as 000F333536333037303432343431303133.
First two bytes denote IMEI length. In this case 0x000F means, that IMEI is 15 bytes long.
After receiving IMEI, server should determine if it would accept data from this module. If yes, server will reply to module 01, if not - 00. Note that confirmation should be sent as binary packet. I.e. 1 byte 0x01 or 0x00.
Then the module starts to send the first AVL data packet. After the server receives a packet and parses it, the server must report to the module number of data received as integer (four bytes).
If sent data number and reported by the server doesn’t match module resends sent data.


Module connects to server and sends IMEI:
Server accepts the module:
Module sends data packet

I am receiving the IMEI and trying to respond with a 01, which should tell the AVL Module to send the remaining data.

Here is my updated flow with the current debugging outputs:

Use a buffer..

Function node...

msg.paylaod = Buffer.from([1]);
return msg;

Attach a debug after the function/before the TCP out node. You will see the payload is a binary buffer containing 1 byte with a value of 1.

Ps, 1 is the same as 0x1 :slight_smile:

Thank you for the feedback. However, I must still have something wrong...

The first debug window (on the top) seems to be dumping the IMEI, which is correct. But I would have assumed the second debug window should be dumping my message payload, which should be a value 01. However, it is also dumping the IMEI.

My new function node has the following:

msg.paylaod = Buffer.from([1]);
return msg;

check again!

1 Like

Hahahah, Awesome! Working great now!

1 Like

One more question... Anyone have any idea why this payload is not in clear text?

Where is it coming from?

Thats your data from the tcp in node, I assume you have to convert it from a buffer to make it readable

EDIT: please be careful with the following steps. Your flow could eventually go into a loop. The function node will continue to send "1" every time it receives a message on the input. Maybe this does not harm your device...or it will go banas

The data is coming from a Teltonika GPS tracking device.

Thank you for the feedback. I tried converting from a buffer to a string, but the data is still not possible to read.

My function:

msg.payload = msg.payload.toString();
return msg;

Your Payload is already a string so calling toString will make no difference. Set your TCP in node to return a buffer.

You will probably need a manual to decipher the values.

Perhaps node-red-contrib-buffer-parser will help you decode the values.

Thank you.. I have changed the TCP IN node to return a buffer, and I am now seeing the following data:

I do have the manual, and when reviewing it, it suggests that I should be receiving a string of data:

Received data in hexadecimal stream:
000000000000004A8E010000016B412CEE000100000000000000000000000000000000010005000100010100010011001D00010010015E2C880002000B000000003544C87 A000E000000001DD7E06A00000100002994

The manual then discusses decoding: