Node-RED + TCP command (Audac)

Good morning everyone, I apologize for my English, I used a translator. I am trying to configure my Audac MTX48 device using Node-RED by sending TCP commands, but I am encountering the following problems:

  • Using Node-RED, they do not work

Node-RED Settings

INJECT msg.payload = #|X001|web|SM01|1|U|r/n (string)

TCP OUT Connect to port 5001 at host 10.0.0.253 I tried both with and without “Close connection after each message is sent?”

DEBUG 15/06/2024, 07:30:13

node: debug 1

msg.payload : string[23]

“#|X001|web|SM01|1|U|r/n”

NODE-RED APP LOG

15 Jun 07:54:28 - [info] [debug:debug 1] #|X001|web|SM01|1|U|r/n

15 Jun 07:54:28 - [info] [tcp out:2] connecting to 10.0.0.253:5001

15 Jun 07:54:28 - [info] [tcp out:2] connected to 10.0.0.253:5001

  • I tried to ping from Node-RED to 10.0.0.253 (Audac) and it works correctly.

How can I resolve the problem? I have also searched the forum but found no solutions.

Thank you for your help.

Is this what you are using? It should be a backslash instead of a forward slash.

\n

You are right, I made a mistake in rewriting the message. I am forwarding the screenshot. This is the code entered (#|X001|web|SM01|1|U|r\n)
The result does not change

I also tried with TCP/request. The Audac responds with a command (#|web|X001|VU|000^000^000^000^287^330^320^293^000^000|U|) but does not perform any action on the amplifier.

Can someone help me solve this problem? I’ve tried a myriad of different options and tests, but I can’t wrap my head around why the commands work perfectly with Packet Sender, yet with Node-Red, despite being able to ping the device correctly (indicating that it can see and communicate with the device), the command fails to execute any operation.

This is not a node or a process I am familiar with. I’ve been on this board for while and the tcp node rarely comes up here. In other words I’m not sure how many users here actually use this to be able to help you.

This process is pure nodered meaning it does not interact with home assistant. Nodered has their own forum and likely has users that have experience using the tcp node. You should try posting there.

Thank you so much for the advice, you’re right, I hadn’t thought of that.

Problems like this can be very difficult to diagnose when you are on your machine, using your set up, and have access to local tools. To do this remotely makes it much harder still, and the real difficulty is that I don’t have an Audac device, so it is just not possible to debug the communication part of the issue.

The Node-RED and the TCP node part I can look at, since I use both and successfully.

I use the TCP request node, and this really is very simple to set up.

The problems are that these nodes are really working with buffers, and not strings. A buffer and a string may look the same, but a buffer is an array of values in the range 0x00 to 0xFF, whereas a string is a array of characters. Humans understand strings, computers understand buffers, and converting between the two is a major source of problems in comms such as here.

In my case, I am feeding commands to a battery console comms port, as if I was typing in the command, so I am sending in a string. I am expecting a response, as I would see on a console, so I am asking for a string back. The complex bit is adding in the necessary ‘new-line’ characters to make it work.

For me, as I am using Linux, the newline is represented by \n, and I need two of them. One terminates the command, the other gets consumed somewhere, either the TCP node or my console port, so I have added an extra one just to make it work.

Taking the time and trouble to read the manual you link to, I note

Command overview
Startsymbol|destination|source|command|argument’s|checksum|stopsymbol
Example: Set volume zone 1 to -30dB ASCII #|X001|web|SV1|30|U|return

Important:- The address of the MTX is fixed at X001.- The checksum is CRC-16 excluding the ‘#’. You can replace the checksum with ‘U’, this is always accepted as checksum.- return = 0x0d 0x0a- source address has a maximum length of 4 characters and cannot contain “|” or “#”

This clearly states that the command end terminator is ‘return’ which is 0x0d 0x0a

I note that you are sending r\n in your packet sender, which is showing in the Hex as 72 0a, so this is not correct. I have no idea why it is working, but it probably should be \r\n. Some software (particularly on PCs) takes \n to be a CR LF which is both 0d and 0a, so I am assuming that your packet sender is fudging it to work, whereas on a Linux machine it will not.

You don’t show your node settings (which make it impossible to debug these for you). If you want to keep the connection open (which I do as I am sending commands every 30 seconds or so) and if you are sending in a string and not a buffer (which I am) and if you want to get a string response back, you may need to play with the delimiter option. Sometimes you just have to fiddle with the settings until it all suddenly springs into life.

A great way to test all of this is to use a command that will always generate a known response (‘hello world’). You have the 'Get Firmware Version or GSV. This should return a string

Get the firmware version
Example Command #|X001|web|GSV|0|U|return
Answer #|web|X001|SV|V1.1|U|return

Since this is not dependent on having a valid instruction, it would test the send-response to at least know you have the correct command sequence and terminators, and your TCP node is working.

In the end, debugging TCP comms comes down to using the packet sender you have, and also using the TCP node and checking the input and output as a buffer, and checking each hex value to see exactly what is going on. Tedious, but sometimes necessary.

1 Like

Wow, what preparation! By carefully reading your post, I managed to send the first commands, and they work. Among the various tests, I created a function that converts msg.payload into a buffer, and it takes the command correctly.

In the coming days, I will try to configure as much as possible, and if I encounter difficulties, I will take the opportunity to write again if possible, given the high technical preparation.

For now, thank you very much.

Code used for the function:

// Extracts the value of msg.payload and converts it into a string
let command = String(msg.payload);

// Replaces literal characters \r and \n with actual characters
command = command.replace(/\\r/g, '\r').replace(/\\n/g, '\n');

// Log to verify the extracted command
node.warn(`Command: ${command}`);

// Converts the command into a buffer using 'ascii' encoding
msg.payload = Buffer.from(command, 'ascii');

host = global.get("host");

// Log to verify the converted buffer
node.warn(`Buffer: ${msg.payload.toString('hex')}`);

return msg; // Returns the modified message

I made this code by searching online and with the help of ChatGPT. If you have any advice, it is always welcome.

I had to use this code (command = command.replace(/\r/g, ‘\r’).replace(/\n/g, ‘\n’):wink: because otherwise, it would not create the correct buffer. With this modification, which I honestly understood little about, it works.

Feel free to reach out if you need any further assistance!

Thanks to your help I managed to get my Audac MTX48 working. If it can be useful to anyone I can forward you the Node-red flow. Thanks for the essential help

Hi Sacrima,

I would be interested to receive your example flow for Audac !

Thanks a lot in advance.

Best Regards,

Hi Sacrima,

I would also be interested in receiving your Audac example process!

Thank you so much.