# How to get temperature values below zero

**URL:** https://discourse.nodered.org/t/how-to-get-temperature-values-below-zero/42383
**Category:** General
**Created:** [10 March 2021 07:26 UTC](https://discourse.nodered.org/t/how-to-get-temperature-values-below-zero/42383 "2021-03-10T07:26:32Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Noschvie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/noschvie/32/21425_2.png) [@Noschvie](https://discourse.nodered.org/u/Noschvie)
#### Post date: [10 March 2021 07:26 UTC](https://discourse.nodered.org/t/how-to-get-temperature-values-below-zero/42383/1 "2021-03-10T07:26:32Z")

</div>

Hello,  
using Modbus to get the outdoor temperature value with the range of negative numbers too.  
Reading the Modbus address works fine and gets the data as:

```auto
Kessel (1) : msg.payload : Object
object
data: array[1]
0: 65533
buffer: buffer[2]
0: 0xff
1: 0xfd

```

The connected device sends the temperature value multiplied by 10 (1,5 °C -\> 15) as INT16 (signed value).  
But how have this value be handled in Node-RED to devide by 10 and get negative numbers too?

```auto
msg.payload = msg.payload[0] / 10;
return msg;

```

Node-RED seems to use an unsigned value, how to use as signed value or cast / convert to signed?  
Thanks!

---

<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: [10 March 2021 07:56 UTC](https://discourse.nodered.org/t/how-to-get-temperature-values-below-zero/42383/2 "2021-03-10T07:56:36Z")

</div>

As it is only 1 field, a call to the buffer functions is really all it takes to solve this, however, there is a node that simplifies this - node-red-contrib-buffer-parser

Demo...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/011a46cc38d22afb1b50bbea36b71b3dcd61c731.png)

```auto
[{"id":"cad1ac8d.36dc","type":"function","z":"1f9c7e1a.6fad92","name":"fake the modbus data","func":"//fake the modbus data\nmsg.payload = {};\nmsg.payload.data = [65533];\nmsg.payload.buffer = Buffer.from([0xff, 0xfd])\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1680,"y":140,"wires":[["3126af75.ff23a","32cbecbd.e13de4"]]},{"id":"3021ca58.1ecc16","type":"inject","z":"1f9c7e1a.6fad92","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1660,"y":80,"wires":[["cad1ac8d.36dc"]]},{"id":"3126af75.ff23a","type":"buffer-parser","z":"1f9c7e1a.6fad92","name":"","data":"payload.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"temperature","offset":0,"length":1,"offsetbit":0,"scale":"/ 10","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":1910,"y":140,"wires":[["c82c506a.a5897"]]},{"id":"c82c506a.a5897","type":"debug","z":"1f9c7e1a.6fad92","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2090,"y":140,"wires":[]},{"id":"32cbecbd.e13de4","type":"function","z":"1f9c7e1a.6fad92","name":"manual calulation","func":"var temp = msg.payload.buffer.readInt16BE(0);\ntemp /= 10;\nmsg.payload = {\n temperature: temp\n} \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1890,"y":180,"wires":[["8b66d58d.9ae8b8"]]},{"id":"8b66d58d.9ae8b8","type":"debug","z":"1f9c7e1a.6fad92","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2090,"y":180,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![Noschvie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/noschvie/32/21425_2.png) [@Noschvie](https://discourse.nodered.org/u/Noschvie)
#### Post date: [10 March 2021 08:24 UTC](https://discourse.nodered.org/t/how-to-get-temperature-values-below-zero/42383/3 "2021-03-10T08:24:42Z")

</div>

Thanks, "fast as the wind"!  
"buffer parser" shows this msg:  
`"TypeError: scale.matchAll is not a function"`  
What is missing?  
Norbert

---

<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: [10 March 2021 08:27 UTC](https://discourse.nodered.org/t/how-to-get-temperature-values-below-zero/42383/4 "2021-03-10T08:27:13Z")

</div>

> [@Noschvie](#):
>
> "TypeError: scale.matchAll is not a function"

What version of NODE are you running? enter `node -v` in a terminal or cmd window

what version of buffer parser do you have installed? (check in the "palette" -\> installed)

NOTE: I am the author of that node so would appreciate figuring that out. 🙂

Cheers.

#### EDIT...

I suspect that you are using NODE V10 (or less) as `matchAll` was introduced in Node v12.

NOTE: NODE10 is End of Life in in April so I am not overly keen to alter the code.

Let me know either way.

---

<div class="post-metadata">

### Author: ![Noschvie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/noschvie/32/21425_2.png) [@Noschvie](https://discourse.nodered.org/u/Noschvie)
#### Post date: [10 March 2021 09:45 UTC](https://discourse.nodered.org/t/how-to-get-temperature-values-below-zero/42383/5 "2021-03-10T09:45:39Z")

</div>

Running as docker container @RPi 4 with:

```auto
image: nodered/node-red:latest

```

and yes, it's v10.23.1

---

<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: [10 March 2021 09:55 UTC](https://discourse.nodered.org/t/how-to-get-temperature-values-below-zero/42383/6 "2021-03-10T09:55:28Z")

</div>

I don't use docker (more trouble than its worth imo)

I am surprised latest is targeting node V10. Perhaps there is an update to that image? How long ago did you install it?

Ps, I'm case you were not aware (I'm sure you are), there is a simple setup script for installing node-red natively on the pi?

---

<div class="post-metadata">

### Author: ![Noschvie](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/noschvie/32/21425_2.png) [@Noschvie](https://discourse.nodered.org/u/Noschvie)
#### Post date: [10 March 2021 10:09 UTC](https://discourse.nodered.org/t/how-to-get-temperature-values-below-zero/42383/7 "2021-03-10T10:09:11Z")

</div>

Changed container to  
`image: nodered/node-red:latest-12`  
and it works great! Thanks!

---

<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: [24 March 2021 10:10 UTC](https://discourse.nodered.org/t/how-to-get-temperature-values-below-zero/42383/8 "2021-03-24T10:10:09Z")

</div>

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