# Convert Modbus data to ACC64 (buffer-parser, Ohmpilot, SunSpec)

**URL:** <https://discourse.nodered.org/t/convert-modbus-data-to-acc64-buffer-parser-ohmpilot-sunspec/89392>\
**Category:** General\
**Created:** [10 July 2024 07:07 UTC](https://discourse.nodered.org/t/convert-modbus-data-to-acc64-buffer-parser-ohmpilot-sunspec/89392 "2024-07-10T07:07:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cholzer79](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cholzer79/32/92702_2.png) [@cholzer79](https://discourse.nodered.org/u/cholzer79)\
**Post date:** [10 July 2024 07:07 UTC](https://discourse.nodered.org/t/convert-modbus-data-to-acc64-buffer-parser-ohmpilot-sunspec/89392/1 "2024-07-10T07:07:35Z")

</div>

Hello!  
I fetch 4 modbus registers which use the type "ACC64" for total powerconsumption in Wh.

So far I utterly failed to convert the buffer to a number. Could anyone please help me how to configure the buffer parser? 🙂

Thank you very much! 🙂

---

<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 July 2024 08:10 UTC](https://discourse.nodered.org/t/convert-modbus-data-to-acc64-buffer-parser-ohmpilot-sunspec/89392/2 "2024-07-10T08:10:59Z")

</div>

Hi, welcome to the forum.

I am unfamiliar with ACC64 but a quick search reveals it is a number format SunSpec uses - are you using SunSpec gear?

According to a [Sunspec PDF](https://sunspec.org/wp-content/uploads/2021/02/SunSpec-Device-Information-Model-Specificiation-V1-0-02-01-2021.pdf), ACC64 is essentially a smaller `uint64` with a range of `0 ... 9223372036854775807`

`9223372036854775807` is bigger than JavaScripts Number.MAX\_SAFE\_INTEGER so you likely need to use BigInt value (which is a true 64bit number)

Can you copy the output of the Modbus node and paste it in a reply. Also, tell us the value you expect the 4 UINT16 modbus values to be once converted.

e.g.

### Modbus node debug capture:

```auto
{ payload: [0,0,16,55432], xxx: {], yyy: {}, zzz:{} }

```

### Expected value:

`203685477`

  

* * *

### How to grab data from a node

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path/value for any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

### How to post data values

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![cholzer79](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cholzer79/32/92702_2.png) [@cholzer79](https://discourse.nodered.org/u/cholzer79)\
**Post date:** [10 July 2024 08:21 UTC](https://discourse.nodered.org/t/convert-modbus-data-to-acc64-buffer-parser-ohmpilot-sunspec/89392/3 "2024-07-10T08:21:15Z")

</div>

Hey Steve, thank you for your reply! 🙂

> [@Steve-Mcl](#):
>
> I am unfamiliar with ACC64 but a quick search reveals it is a number format SunSpec uses - are you using SunSpec gear?

Correct, I use a Fronius Gen24+ Inverter and Fronius Ohmpilot, they use Sunspec.

> [@Steve-Mcl](#):
>
> Can you copy the output of the Modbus node and paste it in a reply. Also, tell us the value you expect the 4 UINT16 modbus values to be once converted.

This is the output. As the Ohmpilot is brand new, I expect the Wh Lifetime Energy Consumption to be very low. But I dont know the exact value.

```auto
{"data":[0,0,0,240],"buffer":[0,0,0,0,0,0,0,240]}

```

---

<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 July 2024 08:34 UTC](https://discourse.nodered.org/t/convert-modbus-data-to-acc64-buffer-parser-ohmpilot-sunspec/89392/4 "2024-07-10T08:34:41Z")

</div>

> [@cholzer79](#):
>
> This is the output. As the Ohmpilot is brand new, I expect the Wh Lifetime Energy Consumption to be very low. But I dont know the exact value.

Given this info, i assume my effort is correct

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

As i hinted to earlier, this is a 64bit value so the solution is to use [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt). However, BigInt can be tricky to work with so I included a means of converting it to a regular number - BUT if it goes beyond `Number.MAX_SAFE_INTEGER` (`9007199254740991`) then you will start to lose precision. If you beleive this will NEVER get anywhere near that value, then thats fine. If you expect to reach that kind of number, remove the "as regular number" function and use the 64bit bigInt that buffer parser outputs.

Demo flow (use `ctrl-i` to import)

```auto
[{"id":"d7de344b8c78bc75","type":"buffer-parser","z":"6f432348c57a2fda","name":"","data":"payload.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"bigint64be","name":"powerconsumptionWh","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":1340,"y":420,"wires":[["7123d04b8c8db4b1","fa8a66bcfa6e7650"]]},{"id":"ab925aeaf3a588fb","type":"inject","z":"6f432348c57a2fda","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1190,"y":360,"wires":[["07302e0635406247"]]},{"id":"07302e0635406247","type":"function","z":"6f432348c57a2fda","name":"your data","func":"\nmsg.payload = {\"data\":[0,0,0,240],\"buffer\":Buffer.from([0,0,0,0,0,0,0,240])}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1350,"y":360,"wires":[["d7de344b8c78bc75"]]},{"id":"7123d04b8c8db4b1","type":"debug","z":"6f432348c57a2fda","name":"debug 42","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1550,"y":420,"wires":[]},{"id":"fa8a66bcfa6e7650","type":"function","z":"6f432348c57a2fda","name":"as regular number","func":"\n// NOTE: regular numbers are much easier to work with but\n// have a MAX value of (2^53 – 1) = 9007199254740991\n\nconst max = BigInt(Number.MAX_SAFE_INTEGER)\nif (msg.payload.powerconsumptionWh > max) {\n node.warn(\"powerconsumptionWh is bigger than MAX_SAFE_INTEGER, precision may be lost\");\n}\nmsg.payload.powerconsumptionWh = Number(msg.payload.powerconsumptionWh)\n\nreturn msg\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1380,"y":500,"wires":[["ed2a804fddbccf40"]]},{"id":"ed2a804fddbccf40","type":"debug","z":"6f432348c57a2fda","name":"debug 43","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1560,"y":500,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![cholzer79](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cholzer79/32/92702_2.png) [@cholzer79](https://discourse.nodered.org/u/cholzer79)\
**Post date:** [10 July 2024 08:38 UTC](https://discourse.nodered.org/t/convert-modbus-data-to-acc64-buffer-parser-ohmpilot-sunspec/89392/5 "2024-07-10T08:38:09Z")

</div>

You are a true legend! 🙇‍♂️  
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:** [24 July 2024 08:38 UTC](https://discourse.nodered.org/t/convert-modbus-data-to-acc64-buffer-parser-ohmpilot-sunspec/89392/6 "2024-07-24T08:38:19Z")

</div>

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