# Modbus query SMA Inverter - the right way

**URL:** <https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400>\
**Category:** General\
**Created:** [27 September 2020 09:36 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400 "2020-09-27T09:36:39Z")\
**Posts on this page:** 15\
**Page:** 2

<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 September 2020 14:00 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/22 "2020-09-28T14:00:48Z")

</div>

> [@dceejay](#):
>
> well 2147483648 is 0x80000000 in hex so looks suspiciously like a signed int overflow

Good spot.

> [@Becker](#):
>
> here a formula / expression "if msg.payload \< 0 than give 0 to output"

That might be necessary. It may be that the inverter deliberately sends this value when there its value is invalid / empty. Doe the value look normal when operating during the day?

> [@Becker](#):
>
> I'm still waiting for the answer from @Steve-Mcl

Life beckons, might get 5 minutes later this evening.

---

<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:** [28 September 2020 14:36 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/23 "2020-09-28T14:36:26Z")

</div>

> [@Steve-Mcl](#):
>
> That might be necessary. It may be that the inverter deliberately sends this value when there its value is invalid / empty. Doe the value look normal when operating during the day

Yes, all values are normal when the inverter(s) are online, as you see in my screenshot ([https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2e733f5307cd1bee5a79db5a3736ee78adf9a9af.png](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2e733f5307cd1bee5a79db5a3736ee78adf9a9af.png))

Can someone tell me a function expression with "if ... msg.payload receive = -2147483648 than make value = 0" 🤪

---

<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:** [28 September 2020 14:40 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/24 "2020-09-28T14:40:38Z")

</div>

```auto
if (msg.payload == -2147483648 ) {
    msg.payload = 0;
}
return msg;

```

by the way your devices are Sunny boy and tripower .. each have their own seperate addresses or is the modbus address table common ?

---

<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:** [28 September 2020 14:47 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/25 "2020-09-28T14:47:45Z")

</div>

thank you,

each have their own IP adress

---

<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:** [28 September 2020 14:58 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/26 "2020-09-28T14:58:12Z")

</div>

ok .. IP i understand that its different ..  
im talking about the manual / document that you see the list of modbus adresses.  
(you shared one with Google Drive at some point)

Each device has seperate list of addresses or is it for both devices the same ?  
for example address 30769 refers to the same value for Sunny Boy as it does for Tripower ?

---

<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:** [28 September 2020 15:38 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/27 "2020-09-28T15:38:36Z")

</div>

many registers are same, the SB3000TL-21 does not have its own document. I just found the big brothers " STP 15000TL-30 / STP 17000TL-30 / STP 20000TL-30 / STP 25000TL-30".

> **[dok.zip](https://drive.google.com/file/d/1xmHvv0x5smtx4wXkkHLJzk2UKSezOtgq/view?usp=sharing)**
>
> Google Drive file.

and tried it out.

the STP6 reads out the energy meter, so I can query the energy meter (has no modbus, just speedwire) by quering the STP6 modbus.

---

<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:** [28 September 2020 20:47 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/28 "2020-09-28T20:47:39Z")

</div>

this is my final flow:

> **[flows\_buffer.json](https://drive.google.com/file/d/1QHhss4LSdkBNw3W8Xk0vwnZv8WOblVxR/view?usp=sharing)**
>
> Google Drive file.

  
if anyone is interested 🤓

---

<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:** [28 September 2020 21:34 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/29 "2020-09-28T21:34:37Z")

</div>

nice project .. with your thread and Steves lecture posts i finally learned modbus data types  
more than any youtube video 😉

by the way .. there is some interesting information in [FAQ](https://www.sma.de/en/products/monitoring-control/modbus-protocol-interface.html) of SMA website that may be related to those high negative values at night.

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

---

<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 September 2020 22:13 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/30 "2020-09-28T22:13:58Z")

</div>

> [@UnborN](#):
>
> Steves lecture posts

😳

😂😂😂😂😂😂😂😂

---

<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:** [29 September 2020 05:42 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/31 "2020-09-29T05:42:11Z")

</div>

nice found.

but NaN is not -2147483648 or is it?

---

<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:** [29 September 2020 09:11 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/32 "2020-09-29T09:11:04Z")

</div>

NaN cannot be sent over modbus (only numbers)

#### foreword...

_Remember that `-2147483648` is the same as `0x80000000`_

#### my thoughts on this matter...

It might be undocumented for that inverter that NaN will be sent over modbus as a number with only MSB set (0x80000000)

And since the manual states NaN is essentially zero, you might as well use @UnborN suggestion of `if (msg.payload == -2147483648 ) msg.payload = 0`

Alternatively, you could set the MASK in the buffer parser to simply remove the MSB  
e.g. a MASK of `0x7FFFFFF` will "turn off" the highest bit  
i.e. `0x80000000` will become `0x00000000` which is essentially `0`

---

<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:** [29 September 2020 10:28 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/33 "2020-09-29T10:28:53Z")

</div>

by the way: what means the **0x** before the value in hex ?

---

<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:** [29 September 2020 10:34 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/34 "2020-09-29T10:34:09Z")

</div>

> [@Becker](#):
>
> what means the **0x** before the value in hex

its how you specify a value is hexadecimal in JS (and many other languages).

```auto
var a = 0x8000;
console.log(a); // --> outputs 32768

```

Also, its so you (the reader) can see that it is hexadecimal 🙂

Similar to octal...

```auto
let o = 0o51;
console.log(o); // --> outputs 41

```

---

<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:** [30 September 2020 06:13 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/35 "2020-09-30T06:13:17Z")

</div>

@Steve-Mcl I mentioned you with praise on my blog: [Link](http://hausbau-becker.blogspot.com/2020/09/modbus-integration-in-node-red-von-sma.html)  
if you feel like it, you can take a look over it (with translating tool) and tell me if there are mistakes.

---

<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:** [14 October 2020 06:13 UTC](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400/36 "2020-10-14T06:13:17Z")

</div>

Closed on 14 October 2020 06:13 UTC

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

[Previous page](https://discourse.nodered.org/t/modbus-query-sma-inverter-the-right-way/33400.md?page=1)
