Sending UDP message with backslash

Hello,

I'm trying to send the following UDP message in Node-Red:

\apple

But the UDP message being received by the server is:

\\apple

I've been pulling my hair out for a couple of hours trying to come up with a fix and am still struggling. Could anyone help with a solution to this?

Chris

just tried a simple test sending to/from same machine and that seems to work OK

Does a simple local test work for you?

Hi cymplecy,

This is the same behaviour as I get in the node-red gui. But when I recieve the packet in PacketSender an additional backslash has been added (screenshots below).

I have, however come up with a solution in that I am using a function to generate the message in hex and then send it in hex. This has solved my problem and is giving the desired result:

var hexString = "5C6170706C65"; // Hexadecimal string to send
var buffer = Buffer.from(hexString, 'hex');
msg.payload = buffer;
return msg;

Chris

1 Like

If you look at the Hex display in your screenshot you will see that the second \ does not actually exist. My guess is that it is being escaped on the display. What does that display look like when you send it as hex?

Well spotted!! I hadn't noticed that.

I'm sending the string as hex now and the ascii is displaying correctly with just the single backslash.

Chris

Interesting, and confusing.

If you use the inject node to inject a string then it will escape the \ by adding another \ so \apple becomes \\apple - same as if you try to send hello\n to add a carriage return it will send hello\\n as a string... and not with a carriage return character that you want.

You can get round this by setting it to send Json (J) mode instead of String mode - as then "\apple" (now you have to add quotes as well to make it valid JSON) - will then get sent correctly

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.