TCP Output String control character Handling

#1

Please fix the TCP Output Node.
The TCP Output requires special consideration if you need to append the sent string with control characters. You apparently need a function node in your flow to fix the apparent problem. If it is not going to be addressed, then it needs to have a reference in the "Info Tab". This has been an known issue since at least 11/15/2015.
Kind Regards,
Kyle Young

"Nick O'Leary, 11/15/15
The inject node does handle escape sequences like \n - it treats them as literal strings.
For now, use a Function node after your Inject node to append the newline:
msg.payload = msg.payload + '\n';
return msg;
Nick"

0 Likes

#2

The TCP Output node does handle them as if you add them in a function it works...

0 Likes

#3

As Mark says, there is nothing to fix here. The TCP out node sends what it is given.

There are multiple ways to append a newline character - but the 'string' type of the Inject node isn't one of them.

0 Likes

#4

Nick,
OK, I understand. I guess I just misunderstood your comment which I quoted you saying... "For now, use a Function node...". I apparently misinterpreted your comment as there were planned changes ahead for this matter. Also, if there are no further changes planned... Please update the "Info Tab" such that it explains you cannot use (\r\n) escape characters in your string. There is literally no feedback from the node information so it is difficult to know what is wrong if your system is expecting something specific. I tried exposing the message, but nothing was on the output of the TCP Request node...
Thanks,
Kyle

0 Likes

#5

The Inject node's help says:

Local_Node-RED

But yes, that certainly can be improved.

0 Likes

#6

ukmoose,
I got it to work using Nicks information in the quotes. Thus, I used a function to support the control characters... Yes, My point is not that you can get it to work with this work-around, which is all fine, but please either do one of the following.

  1. Fix it such that you can put the control codes in the node itself...
  2. Edit the "Info Tab" to let people know that you will not be able to put the control characters in your string to the msg.Payload....
0 Likes

#7

Nick,
you are the man !
Thank you for your kind and patient response.

Kyle

0 Likes

#8

It's too bad I did not look in the injection node help for the answers.. I'm glad that's there, by-the-way.. although I had no idea it was an injection issue until I found your quote.

Hey, I'm just trying to point out a potential problem and help the users.. I wasted a long time trying to get this work. I should have googled it earlier, but I thought it would be easier. I'm not trying to criticize you guys. I am really very happy with what this does for me.

Kyle

0 Likes

#9

@hp_apcc BTW, the function node is no longer your only choice. You can use a change node to insert control characters into a payload.

1 Like

#10

You can also use an inject node with the JSON data type:
"mystring\n" works great...

2 Likes