# 16bit signed temperature from buffer, Dynet protocol

**URL:** <https://discourse.nodered.org/t/16bit-signed-temperature-from-buffer-dynet-protocol/38149>\
**Category:** General\
**Created:** [28 December 2020 17:30 UTC](https://discourse.nodered.org/t/16bit-signed-temperature-from-buffer-dynet-protocol/38149 "2020-12-28T17:30:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![natm](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/natm/32/34373_2.png) [@natm](https://discourse.nodered.org/u/natm)\
**Post date:** [28 December 2020 17:30 UTC](https://discourse.nodered.org/t/16bit-signed-temperature-from-buffer-dynet-protocol/38149/1 "2020-12-28T17:30:14Z")

</div>

Hello all, attempting to create a dashboard of temperatures in Celsius from Dynalite light switches. These are on an RS485 throughout the house, I can see the temperature regular broadcasts in the Windows app.

I've connected to the serial server from Nodered and am parsing bytes off the wire ok, using the [node-red-contrib-buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser) module. But I can't convert the data Hi + Lo bytes back into a decimal/float.

In the Dynet documentation it says the 3rd byte is the opcode and 0x0C indicates data hi low (5th and 6th byte) will contain the temperature.

`0x0C = Actual Temperature (w/o Temperature Offset), as signed fixed point Q7.8 deg celsius (Range -127.99 to 127.99)`

Examples buffer, should be +20.04 degrees celsius:

 ![Screenshot from 2020-12-28 17-26-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/6643bc878e1579e723937a9f66d71123b9954580.png)

Same packet shown in the manager software:

 ![Screenshot from 2020-12-28 17-26-46](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/a/3a94365f1f8d01e45b13f25059d671c4e07b825d.jpeg)

Any help appreciated.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 December 2020 18:23 UTC](https://discourse.nodered.org/t/16bit-signed-temperature-from-buffer-dynet-protocol/38149/2 "2020-12-28T18:23:44Z")

</div>

> [@natm](#):
>
> signed fixed point Q7.8

@natm

That Q format suggests the value will be xxxxxxx.yyyyyyyy - but that is not possible from 2 bytes. It would make more sense if it said Q3.2

Any how, looking at the packet picture, it look like they concatenate bytes [4] and [5] as strings either side of a decimal point.

Here is a demo...

![yVOlmxqKrD](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/312338ee70d6f775348fa1c6bdf93ebdb9e16236.gif)

```auto
[{"id":"1708eb74.dca695","type":"inject","z":"64ce1d00.d049e4","name":"go","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":210,"y":580,"wires":[["9b7c388a.66a0e8"]]},{"id":"9b7c388a.66a0e8","type":"function","z":"64ce1d00.d049e4","name":"0x1c, 23, 0xc, 0x4a, 0x14, 0x4, 0xff, 0x60 (20.04)","func":"msg.payload = Buffer.from([\n 0x1c,\n 23,\n 0xc,\n 0x4a,\n 0x14,\n 0x4,\n 0xff,\n 0x60,\n])\nreturn msg;","outputs":1,"initialize":"","finalize":"","x":470,"y":580,"wires":[["a73927a0.0a7a18"]]},{"id":"f39df2ff.df304","type":"buffer-parser","z":"64ce1d00.d049e4","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int8","name":"Temp1","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int8","name":"Temp2","offset":5,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":990,"y":620,"wires":[["57669557.1ffabc"]]},{"id":"a73927a0.0a7a18","type":"switch","z":"64ce1d00.d049e4","name":"byte[2] == 0xc?","property":"payload[2]","propertyType":"msg","rules":[{"t":"eq","v":"0xc","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":800,"y":620,"wires":[["f39df2ff.df304"]]},{"id":"848663a0.c0b31","type":"debug","z":"64ce1d00.d049e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload.Temperature","statusType":"msg","x":970,"y":660,"wires":[]},{"id":"580decf8.0d6474","type":"inject","z":"64ce1d00.d049e4","name":"go","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":210,"y":620,"wires":[["cd24b823.918d88"]]},{"id":"cd24b823.918d88","type":"function","z":"64ce1d00.d049e4","name":"0x1c, 0x1f, 0xc, 0x4a, 0x16, 0x11, 0xff, 0x49 (22.17)","func":"msg.payload = Buffer.from([\n 0x1c,\n 0x1f,\n 0xc,\n 0x4a,\n 0x16,\n 0x11,\n 0xff,\n 0x49,\n])\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":620,"wires":[["a73927a0.0a7a18"]]},{"id":"5993359a.1ac49c","type":"function","z":"64ce1d00.d049e4","name":"0x1c, 0x1f, 0xc, 0x4a, 0x10, 0x53, 0xff, 0x49 (16.83)","func":"msg.payload = Buffer.from([\n 0x1c,\n 0x1f,\n 0xc,\n 0x4a,\n 0x10,\n 0x53,\n 0xff,\n 0x49,\n])\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":660,"wires":[["a73927a0.0a7a18"]]},{"id":"a5ce6e63.4d84b","type":"inject","z":"64ce1d00.d049e4","name":"go","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":210,"y":660,"wires":[["5993359a.1ac49c"]]},{"id":"57669557.1ffabc","type":"function","z":"64ce1d00.d049e4","name":"to Q3.2","func":"var s1 = msg.payload.Temp1;\nvar s2 = (msg.payload.Temp2 + \"\").padStart(2,\"0\");\nmsg.payload.Temperature = Number(s1 + \".\" + s2);\nreturn msg;","outputs":1,"initialize":"","finalize":"","x":800,"y":660,"wires":[["848663a0.c0b31"]]}]

```

---

<div class="post-metadata">

**Author:** ![natm](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/natm/32/34373_2.png) [@natm](https://discourse.nodered.org/u/natm)\
**Post date:** [28 December 2020 19:13 UTC](https://discourse.nodered.org/t/16bit-signed-temperature-from-buffer-dynet-protocol/38149/3 "2020-12-28T19:13:04Z")

</div>

@Steve-Mcl

That is working great, many thanks for the prompt reply and working solution.

 ![Screenshot from 2020-12-28 19-11-37](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/a/2aca58c68f4a19b322eee749e4f764e1027d183a.png)

Now time for me to get this data onto the MQTT bus and into InfluxDB 🙂

---

<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:** [11 January 2021 19:13 UTC](https://discourse.nodered.org/t/16bit-signed-temperature-from-buffer-dynet-protocol/38149/4 "2021-01-11T19:13:07Z")

</div>

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