# Bufferparser with U64 Modbus

**URL:** https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071
**Category:** General
**Created:** [6 December 2020 09:11 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071 "2020-12-06T09:11:02Z")
**Posts on this page:** 20
**Page:** 4

<div class="post-metadata">

### Author: ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)
#### Post date: [18 December 2020 14:54 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/61 "2020-12-18T14:54:32Z")

</div>

you made my day 😘  
I almost had it, only the offset was wrong. 😒 😏

---

<div class="post-metadata">

### Author: ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)
#### Post date: [21 December 2020 18:49 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/62 "2020-12-21T18:49:26Z")

</div>

After I got the new Node Red I´m able to use the 64bit buffer parser, but my function node don´t like it:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/587d788794cb209e3b08bc8fd07e64084921a3a3.png)

```auto
[{"id":"484de3fc.dbd88c","type":"function","z":"9f6752b0.b55988","name":"Lad","func":"msg.payload = msg.payload.BattLad / 1000;\nmsg.topic = \"BattLad\";\nreturn msg;","outputs":1,"noerr":0,"x":830,"y":2600,"wires":[["6b32c16d.b6668","51829bda.9ae57c"]]},{"id":"eebff845.4ef8e","type":"function","z":"9f6752b0.b55988","name":"Ent","func":"msg.payload = msg.payload.BattEnt / 1000;\nmsg.topic = \"BattEnt\";\nreturn msg;","outputs":1,"noerr":0,"x":830,"y":2660,"wires":[["51829bda.9ae57c","d08f2090.47383"]]},{"id":"a328886e.cec65","type":"ui_text","z":"9f6752b0.b55988","group":"d5972738.a29c7","order":3,"width":0,"height":0,"name":"Ladung gesamt","label":"Ladung gesamt","format":"{{msg.payload}} kWh","layout":"row-spread","x":1100,"y":2600,"wires":[]},{"id":"d9e56ae3.ad8488","type":"ui_text","z":"9f6752b0.b55988","group":"d5972738.a29c7","order":4,"width":0,"height":0,"name":"Entladung gesamt","label":"Entladung gesamt","format":"{{msg.payload}} kWh","layout":"row-spread","x":1110,"y":2660,"wires":[]},{"id":"6b32c16d.b6668","type":"function","z":"9f6752b0.b55988","name":". zu ,","func":"msg.payload = msg.payload.toFixed(2).replace('.', ',');\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":2600,"wires":[["a328886e.cec65"]]},{"id":"d08f2090.47383","type":"function","z":"9f6752b0.b55988","name":". zu ,","func":"msg.payload = msg.payload.toFixed(2).replace('.', ',');\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":2660,"wires":[["d9e56ae3.ad8488"]]},{"id":"7c44097e.a01888","type":"buffer-parser","z":"9f6752b0.b55988","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"biguint64be","name":"BattLad","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"biguint64be","name":"BattEnt","offset":8,"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":570,"y":2600,"wires":[["484de3fc.dbd88c","eebff845.4ef8e"]]},{"id":"d5972738.a29c7","type":"ui_group","name":"SBS 2.5","tab":"69ee5cda.ec1a2c","order":2,"disp":true,"width":"5","collapse":false},{"id":"69ee5cda.ec1a2c","type":"ui_tab","name":"Batterie","icon":"fa-battery-half","order":2,"disabled":false,"hidden":false}]

```

what must I do with the function node ?

---

<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: [21 December 2020 18:57 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/63 "2020-12-21T18:57:02Z")

</div>

Could you provide sample buffer of data to test?

I seen this a while back but thought I had handled it.

Also, what version of buffer parser you using?

* * *

EDIT...

Never mind, it is your function at error.

---

<div class="post-metadata">

### Author: ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)
#### Post date: [21 December 2020 19:03 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/64 "2020-12-21T19:03:47Z")

</div>

```auto
{"topic":"cd1d4476.573438","messageId":"5fe0f1369fefd7c3f6a4f86f","payload":{"BattLad":"76122","BattEnt":"64273"},"queueLengthByUnitId":{"unitId":3,"queueLength":0},"queueUnitId":3,"unitId":3,"modbusRequest":{"value":{"IS":0},"unitid":"3","fc":4,"address":"31397","quantity":"8","messageId":"5fe0f1369fefd7c3f6a4f86f"},"responseBuffer":{"data":[0,0,1,10586,0,0,0,64273],"buffer":[0,0,0,0,0,1,41,90,0,0,0,0,0,0,251,17]},"_msgid":"dd0262c0.2811","originalPayload":[0,0,1,10586,0,0,0,64273],"specification":{"options":{"byteSwap":[],"resultType":"keyvalue","singleResult":true,"msgProperty":"payload","setTopic":true},"items":[{"type":"biguint64be","name":"BattLad","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"","id":0,"value":"76122"},{"type":"biguint64be","name":"BattEnt","offset":8,"length":1,"offsetbit":0,"scale":"1","mask":"","id":1,"value":"64273"}]},"values":["76122","64273"],"objectResults":{"BattLad":{"type":"biguint64be","name":"BattLad","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"","id":0,"value":"76122"},"BattEnt":{"type":"biguint64be","name":"BattEnt","offset":8,"length":1,"offsetbit":0,"scale":"1","mask":"","id":1,"value":"64273"}},"keyvalues":{"BattLad":"76122","BattEnt":"64273"},"arrayResults":[{"type":"biguint64be","name":"BattLad","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"","id":0,"value":"76122"},{"type":"biguint64be","name":"BattEnt","offset":8,"length":1,"offsetbit":0,"scale":"1","mask":"","id":1,"value":"64273"}],"buffer":[0,0,0,0,0,1,41,90,0,0,0,0,0,0,251,17]}

```

the value will rise about +2000kWh = 2.000.000Wh every year

After a liftime of the inverter it can be at 100.000.000Wh

---

<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: [21 December 2020 19:09 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/65 "2020-12-21T19:09:49Z")

</div>

OK, so first up, bigint number constants should be specified with an `n` e.g. 1000n

Basically, you cannot mix bigint and numbers (Im sure I mentioned difficulties with bigint earlier?)

any how, this is the error...

function `Lad`

```auto
msg.payload = msg.payload.BattLad / 1000; //<<<< 1000 is an int!

```

should be ...

```auto
msg.payload = msg.payload.BattLad / 1000n; /// <<< 1000 as a bigint

```

#### BUT - that is not the end of the problem.

When you come to use the payload in the next nodes downstream probably, they likely wont like bigint either!

The only solution is to cast the bigint into a number type & hope (or check) that it [isnt \> max safe integer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)

I propose wherever you have a bigint, that you do this....

```auto
msg.payload = Number(msg.payload.BattLad / 1000n);

```

---

<div class="post-metadata">

### Author: ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)
#### Post date: [21 December 2020 19:18 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/66 "2020-12-21T19:18:02Z")

</div>

hmm

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1ee0b1db8b5727202c22cd37a484cadc0808e8e6.png)  
now its rounded:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75ef3568e556814a43dff126caa2a6a0b2a9ce07.png)

got it:

msg.payload = Number(msg.payload.BattLad / 1n)  
msg.payload = msg.payload / 1000  
msg.topic = "BattLad";  
return msg;

---

<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: [21 December 2020 19:23 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/67 "2020-12-21T19:23:27Z")

</div>

Use this instead...

```auto
msg.payload = Number(msg.payload.BattEnt) / 1000;

```

Also, delete the functions that call `toFixed` and use angular formatting...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/95311d20117c70db519ac0fdede8736b5a54fd51.png)

---

<div class="post-metadata">

### Author: ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)
#### Post date: [21 December 2020 19:30 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/68 "2020-12-21T19:30:33Z")

</div>

better 😀

i use the , for . function  
msg.payload = msg.payload.toFixed(2).replace('.', ',');

because I like the comma between numbers.  
Is there a "angular formatting" for . to , ?

---

<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: [21 December 2020 19:50 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/69 "2020-12-21T19:50:13Z")

</div>

> [@Becker](#):
>
> Is there a "angular formatting" for . to , ?

There is i18n formatting for angular but I dont think it is included with dashboard.

Anyhow, if you are using NODE -v 14 or greater, you can use...  
`number.toLocaleString("de-DE", {minimumFractionDigits: 2});`

e.g...

```auto
var n = Number(msg.payload.BattEnt) / 1000;
msg.payload = n.toLocaleString("de-DE", {minimumFractionDigits: 2}));

```

however, any US or English folk will be very confused 😜

---

<div class="post-metadata">

### Author: ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)
#### Post date: [22 December 2020 06:33 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/70 "2020-12-22T06:33:48Z")

</div>

toLocaleString does´t work.  
I installed NR yesterday !  
v12.20.0 😨

by the way, can I affect the socketid ? --\> "IP:1880/ui/#!/0?socketid=AnUFbQQ1zxQzKf9sAAAL"  
can I change "AnUFbQQ1zxQzKf9sAAAL" to a name that I determine ?

---

<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: [22 December 2020 06:46 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/71 "2020-12-22T06:46:50Z")

</div>

I don't know. Best start a new thread with appropriate title.

---

<div class="post-metadata">

### Author: ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)
#### Post date: [22 December 2020 06:49 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/72 "2020-12-22T06:49:43Z")

</div>

where do I get Node V 14?

---

<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: [22 December 2020 07:13 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/73 "2020-12-22T07:13:08Z")

</div>

How did you install nodejs in the first place?

Did you `apt` install nodejs?

If you use the official node-red script to install node-red you should get node 14 (I think) but nodejs installation will be skipped if you already installed it.

---

<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: [22 December 2020 07:59 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/74 "2020-12-22T07:59:17Z")

</div>

What does  
`apt-cache policy nodejs`  
show?

---

<div class="post-metadata">

### Author: ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)
#### Post date: [22 December 2020 11:30 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/75 "2020-12-22T11:30:34Z")

</div>

I installed Node Red as suggested:

```auto
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

```

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75fbb45ebbc2237b192b1de48aa1778d7df5fd49.png)

🧐

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [22 December 2020 18:20 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/76 "2020-12-22T18:20:35Z")

</div>

The script sees version 12.20 as a valid version and will not upgrade.  
The same we saw with version 10 that was untouched.

I believe you have to first remove node js  
`sudo apt remove nodejs`

then following this [Article](https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions) download and install **Node.js v14.x** :

> #### Using Debian, as root ( use `sudo` )
> 
> curl -sL [https://deb.nodesource.com/setup\_14.x](https://deb.nodesource.com/setup_14.x) | bash -  
> apt-get install -y nodejs

Do another **backup** and you may need to possibly clean node js cache also.  
Somebody with more experience with the procedure can advice you more

---

<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: [22 December 2020 21:47 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/77 "2020-12-22T21:47:20Z")

</div>

Alternatively you should just be able to edit the file `/etc/apt/sources.list.d/nodesource.list` and change all the 12.x in there to 14.x then run  
`sudo apt update`  
`sudo apt full-upgrade`  
which should upgrade nodejs to 14.x as well as upgrading anything else in the system that needs upgrading.

Once you have upgraded nodejs either by this method or the post above then run the install script again as you need to re-install node-red and rebuild any nodes already configured. The script will not downgrade nodejs.

---

<div class="post-metadata">

### Author: ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)
#### Post date: [23 December 2020 06:26 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/78 "2020-12-23T06:26:06Z")

</div>

is there a reason why it installs 12, x instead of 14,x ?  
Isn´t it stable ??

---

<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: [23 December 2020 07:16 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/79 "2020-12-23T07:16:10Z")

</div>

> [@Becker](#):
>
> is there a reason why it installs 12, x

When a new version of nodejs is released there are always some nodes, mostly contrib nodes, that require some work to make them compatible, for that reason the script tends to lag behind a bit in order to allow time for the nodes to catch up. I believe that 14 will become the recommended version fairly soon.

---

<div class="post-metadata">

### Author: ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)
#### Post date: [23 December 2020 09:01 UTC](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071/80 "2020-12-23T09:01:08Z")

</div>

thanks, I have contrib 😄  
I´ll wait

[Previous page](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071.md?page=3)

[Next page](https://discourse.nodered.org/t/bufferparser-with-u64-modbus/37071.md?page=5)
