# Issues with udp node. Extra characters are added

**URL:** <https://discourse.nodered.org/t/issues-with-udp-node-extra-characters-are-added/91143>\
**Category:** General\
**Created:** [20 September 2024 14:24 UTC](https://discourse.nodered.org/t/issues-with-udp-node-extra-characters-are-added/91143 "2024-09-20T14:24:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ygreq](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ygreq/32/28844_2.png) [@ygreq](https://discourse.nodered.org/u/ygreq)\
**Post date:** [20 September 2024 14:24 UTC](https://discourse.nodered.org/t/issues-with-udp-node-extra-characters-are-added/91143/1 "2024-09-20T14:24:55Z")

</div>

Hi folks!

I managed to get input from smart switches and send them via Zigbee2MQTT and Node-RED and OSC / UDP to another app (Cycling '74 Max in my case). You can see how in the attached images.

Now I am trying to control some LED lights in Home Assistant / Node-RED from the other app via OSC / UDP. But I cannot figure out how to separate messages from something like /ha/led01/on and /ha/led02/on to control each individual light

I also tried just using normal messages via UDP set UDP to output a string. And I get a string out from udp in that looks pretty much the same except for an extra comma. But in the debug it says it has some extra 4 index values (in my case 12 instead of 8 for the message /l01/on). If I use an inject node I get 8 index values like I should. And because of this, it is not recognized down the road by other nodes (for example by the change node)

Any idea on how to fix this issues? So firstly how to use OSC to separate the tags. Or how can I get via udp a string with no extra comma and / or without extra 4 index values.

I was thinking as last resort, to extract the extra info from the string but no idea how.

Thank you so much!

 ![Screenshot 2024-09-20 172236](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8ed5ae5cfb7a4528ce97dac60d46644f5ed6fd3b.png)  
 ![Screenshot 2024-09-20 172321](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/e/3ed132b6ed77e72104a386244ddca2372de557c0.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [21 September 2024 04:04 UTC](https://discourse.nodered.org/t/issues-with-udp-node-extra-characters-are-added/91143/2 "2024-09-21T04:04:30Z")

</div>

There may be non-printable characters in the UDP output.

Could you try to send the output through a function node with the following content:

```auto
const input = msg.payload 
msg.payload = input.replace(/[^\x00-\x7F]/g, "");
return msg;

```

It will keep the ASCII characters

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [21 September 2024 08:18 UTC](https://discourse.nodered.org/t/issues-with-udp-node-extra-characters-are-added/91143/3 "2024-09-21T08:18:38Z")

</div>

Udp payload is often binary and should be treated as a buffer. If you convert it to a string the default is to use utf8 which may interpret some binary incorrectly.

---

<div class="post-metadata">

**Author:** ![ygreq](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ygreq/32/28844_2.png) [@ygreq](https://discourse.nodered.org/u/ygreq)\
**Post date:** [21 September 2024 09:19 UTC](https://discourse.nodered.org/t/issues-with-udp-node-extra-characters-are-added/91143/4 "2024-09-21T09:19:24Z")

</div>

Do you know how I can convert the buffer to a string so I can use it as a command? I just want it to be recognized by the _changes_ nodes. So for example if I send a string like this /l01/on from the external app, I get the exact same string to send to change it to on to use it as a specific command to a call service node.

Thank you so much!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 December 2024 09:20 UTC](https://discourse.nodered.org/t/issues-with-udp-node-extra-characters-are-added/91143/5 "2024-12-20T09:20:12Z")

</div>

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