# UDP message -\> get the value

**URL:** <https://discourse.nodered.org/t/udp-message-get-the-value/7808>\
**Category:** General\
**Created:** [10 February 2019 16:42 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808 "2019-02-10T16:42:43Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogier](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@rogier](https://discourse.nodered.org/u/rogier)\
**Post date:** [10 February 2019 16:42 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/1 "2019-02-10T16:42:43Z")

</div>

i got a issue: iam getting a UDP massage from a DDC controller.  
the massage looks like this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/98c981aaf48d9edd5c21f42c187f08a198d844ed.png)  
i know that the value i need is

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f26d1c464f2fdb53e6e3bbc946f908994e7756fd.png)  
can somebody tell me how to isolate the value ?  
thank you

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 February 2019 17:05 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/2 "2019-02-10T17:05:58Z")

</div>

What is the toFloat node and what have you got the inject node configured to do? In other words what do you need the input message converted to? A buffer containing the relevant bytes or a string or what?

---

<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:** [10 February 2019 20:09 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/3 "2019-02-10T20:09:28Z")

</div>

Is it always the bytes 4 to 7 ? Are you ever going to want to decode the first few bytes also ?  
The node-red-contrib-binary node can be useful for unpacking various formats of bytes (but does take a bit of getting used to I'll admit). Otherwise I'd just use a simple function node to slice out the required bytes into another buffer before using you toFloat node

[https://nodejs.org/api/buffer.html#buffer\_buf\_slice\_start\_end](https://nodejs.org/api/buffer.html#buffer_buf_slice_start_end)

---

<div class="post-metadata">

**Author:** ![rogier](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@rogier](https://discourse.nodered.org/u/rogier)\
**Post date:** [10 February 2019 20:31 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/4 "2019-02-10T20:31:30Z")

</div>

Thank you for the info,  
the value is always in buffer 4-8.  
i got the isolation of the value now working. but its a float value. the ToFloat function is not working....

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8bb6692fdb5695fbefa2d67a1b859bfe0ce053fc.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/1a3a0a12bbfe998fd1c39d263739347c2779582b.png)

now iam fighting to get the isolated hex value in a decimale value.

---

<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:** [10 February 2019 20:42 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/5 "2019-02-10T20:42:29Z")

</div>

Using the [https://flows.nodered.org/node/node-red-contrib-binary](https://flows.nodered.org/node/node-red-contrib-binary) node you can inject the original 8 bytes and get the result you want using the pattern `x32,l32f` - which means skip the first 32 bits (=4 bytes) - then read the next 32 as a little endian floating point number.

```auto
[{"id":"4dab4f20.69247","type":"inject","z":"8eaef9ed.138468","name":"","topic":"","payload":"[\"0xfa\",\"0x41\",\"0x2\",\"0x1\",\"0x41\",\"0x1a\",\"0x25\",\"0x2d\"]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"hide":false,"x":130,"y":560,"wires":[["a067bf73.125a7"]]},{"id":"a067bf73.125a7","type":"binary","z":"8eaef9ed.138468","name":"","pattern":"x32,l32f","x":290,"y":560,"wires":[["a8172873.d7ecf8"]]},{"id":"a8172873.d7ecf8","type":"debug","z":"8eaef9ed.138468","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":560,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![rogier](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@rogier](https://discourse.nodered.org/u/rogier)\
**Post date:** [10 February 2019 20:59 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/6 "2019-02-10T20:59:00Z")

</div>

This is magic!! this is working without a function node!

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e3b2771068aa3ad81b12c4666060a52b401d33ff.png)

thank you very much!!

now going to check to receive a single bit value...

---

<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:** [10 February 2019 21:05 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/7 "2019-02-10T21:05:21Z")

</div>

The binary node can also extract bits - but as I said the pattern "language" used takes a bit of understanding - [https://github.com/bigeasy/packet#binary-pattern-fields](https://github.com/bigeasy/packet#binary-pattern-fields)

---

<div class="post-metadata">

**Author:** ![rogier](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@rogier](https://discourse.nodered.org/u/rogier)\
**Post date:** [14 February 2019 20:02 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/8 "2019-02-14T20:02:54Z")

</div>

reading is not a problem anymore... thanks to you. now i tried to write.  
with wireshark i capture the write HEX string.  
when i inject this to the UDP port the value is written. but when i change the value it doesn't work.  
this works:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/55fe7c3e4c72817c9965a9add5942083491c913e.png)  
Bleu is the float value.. (60)  
if i change this to 40 it shoud look like this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d25e4bbf88a0ddc052c9c165b588f98998f76406.png)

but that doesn't work...

any idea?

---

<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:** [14 February 2019 20:24 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/9 "2019-02-14T20:24:44Z")

</div>

You are sending an ascii string... ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a4b45677daf1854ec465c79426e8df779434053d.png)

you need to send a binary packet

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/29f98d3585b8209b2dfc495f62f3689a6a8f6b2d.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/71eaa97ef985990555d0231e87cd643a11b28b66.png)

but use all your values instead .. not easy to type I'll admit

---

<div class="post-metadata">

**Author:** ![rogier](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@rogier](https://discourse.nodered.org/u/rogier)\
**Post date:** [14 February 2019 20:31 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/10 "2019-02-14T20:31:28Z")

</div>

ok, but i got a HEX function between de injection and udp.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a44ff99f5a498b39cb30d9632f4846f34603a104.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cafd2ae779b10dc1d43577f270e23fdc9ef7eb34.png)

the injection writes the 60 but not the 40 value.

when i capture with wireshark a write 40 it looks like this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/03140d95654caac2c5f3a9d3332cbf147c432cf9.png)

and that is also working.. but i want to use a dashboard slider for writing a value..

---

<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:** [14 February 2019 21:57 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/11 "2019-02-14T21:57:58Z")

</div>

ah - you may need to use the binary node again to re-encode the parts  
eg

````auto
[{"id":"1da2f63a.0073aa","type":"binary","z":"82738787.0e0338","name":"","pattern":"x32,l32f","x":370,"y":660,"wires":[["f95b989a.bd4358"]]},{"id":"f95b989a.bd4358","type":"debug","z":"82738787.0e0338","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":660,"wires":[]},{"id":"8728002d.7341a","type":"inject","z":"82738787.0e0338","name":"","topic":"","payload":"{\"a\":9.3}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"hide":false,"x":160,"y":660,"wires":[["1da2f63a.0073aa"]]}]```
````

---

<div class="post-metadata">

**Author:** ![rogier](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@rogier](https://discourse.nodered.org/u/rogier)\
**Post date:** [16 February 2019 11:27 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/12 "2019-02-16T11:27:00Z")

</div>

pow, that goes a bit to fast for me.. can i hook a slider to this and get the correct value?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/922ff071a51ddeb696f5ae34d39ccbbea73c1e16.png)

i got an error..

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [16 February 2019 11:36 UTC](https://discourse.nodered.org/t/udp-message-get-the-value/7808/13 "2019-02-16T11:36:28Z")

</div>

Sure, you just need to `change` the data out of the slider into the format the binary node expects.
