Strange modbus float32 value

I have TCP slave with config:

Bridge modbus:tcp:elcounter [ host="192.168.0.30", id="1" ] {
        Bridge poller elcounter_slave2 [ start="4", length=2, type="input" ] {
           Thing data elcounter_slave2_test [ readStart="4", readValueType="float32" ]
        }
}

As result I receive value like 921974826045060800000000.

What is wrong with my config?

I tried get value with TCP master, it looks like device return correct values:

1 Like

Modbus does everything in 16-bit registers. There are no rules about using a register pair A+B or as B+A for a 32-bit format. Try the other format -

Openhab able to work with 32 bit float.
I have another device on RS485 bus with similar config:

Bridge modbus:serial:elcounter [ port="/dev/ttyU0", id="11", baund="9600", parity="none", dataBits="8", encoding="rtu", stopBits="1.0" ] {
        Bridge poller elcounter_slave1 [ length=2, type="input" ] {
           Thing data elcounter_slave1_voltage [ readStart="0", readValueType="float32" ]
        }
        Bridge poller elcounter_slave2 [ start="6", length=2, type="input" ] {
           Thing data elcounter_slave2_current [ readStart="6", readValueType="float32" ]
        }
        Bridge poller elcounter_slave3 [ start="70", length=2, type="input" ] {
           Thing data elcounter_slave3_freq [ readStart="70", readValueType="float32" ]
        }
        Bridge poller elcounter_slave4 [ start="12", length=2, type="input" ] {
           Thing data elcounter_slave4_a_power [ readStart="12", readValueType="float32" ]
        }
        Bridge poller elcounter_slave5 [ start="36", length=2, type="input" ] {
           Thing data elcounter_slave5_cos [ readStart="36", readValueType="float32" ]
        }
        Bridge poller elcounter_slave6 [ start="342", length=2, type="input" ] {
           Thing data elcounter_slave6_power_a_all [ readStart="342", readValueType="float32" ]
        }
}

With this device i see float values without issues. Some lines from log:

2019-10-13 20:30:24.234 [vent.ItemStateChangedEvent] - HOME_POWER_FREQ changed from 50.00015640258789 to 50.010223388671875
2019-10-13 20:30:24.314 [vent.ItemStateChangedEvent] - HOME_POWER_A_POWER changed from 805.3080444335938 to 803.90087890625
2019-10-13 20:30:24.394 [vent.ItemStateChangedEvent] - HOME_POWER_CURRENT changed from 3.634546995162964 to 3.6293625831604004
2019-10-13 20:30:24.954 [vent.ItemStateChangedEvent] - HOME_POWER_CURRENT changed from 3.6293625831604004 to 3.641164541244507
2019-10-13 20:30:25.034 [vent.ItemStateChangedEvent] - HOME_POWER_VOLTAGE changed from 228.91236877441406 to 229.0161590576172
2019-10-13 20:30:25.178 [vent.ItemStateChangedEvent] - HOME_POWER_COS changed from -14.622182846069336 to -14.64127254486084
2019-10-13 20:30:25.338 [vent.ItemStateChangedEvent] - HOME_POWER_FREQ changed from 50.010223388671875 to 50.0013427734375
2019-10-13 20:30:25.418 [vent.ItemStateChangedEvent] - HOME_POWER_A_POWER changed from 803.90087890625 to 806.80517578125
2019-10-13 20:30:25.977 [vent.ItemStateChangedEvent] - HOME_POWER_A_POWER changed from 806.80517578125 to 799.7874145507812
2019-10-13 20:30:26.057 [vent.ItemStateChangedEvent] - HOME_POWER_CURRENT changed from 3.641164541244507 to 3.6101107597351074
2019-10-13 20:30:26.137 [vent.ItemStateChangedEvent] - HOME_POWER_VOLTAGE changed from 229.0161590576172 to 228.9873504638672
2019-10-13 20:30:26.281 [vent.ItemStateChangedEvent] - HOME_POWER_COS changed from -14.64127254486084 to -14.653048515319824
2019-10-13 20:30:26.441 [vent.ItemStateChangedEvent] - HOME_POWER_FREQ changed from 50.0013427734375 to 49.99134063720703
2019-10-13 20:30:26.921 [vent.ItemStateChangedEvent] - HOME_POWER_A_ALL changed from 3688.154052734375 to 3688.155029296875
2019-10-13 20:30:26.922 [vent.ItemStateChangedEvent] - HOME_POWER_A_REAL changed from 15984.394052734375 to 15984.395029296875
2019-10-13 20:30:27.001 [vent.ItemStateChangedEvent] - HOME_POWER_FREQ changed from 49.99134063720703 to 50.00960922241211
2019-10-13 20:30:27.081 [vent.ItemStateChangedEvent] - HOME_POWER_A_POWER changed from 799.7874145507812 to 807.56640625
2019-10-13 20:30:27.161 [vent.ItemStateChangedEvent] - HOME_POWER_CURRENT changed from 3.6101107597351074 to 3.645287275314331
2019-10-13 20:30:27.241 [vent.ItemStateChangedEvent] - HOME_POWER_VOLTAGE changed from 228.9873504638672 to 228.86233520507812
2019-10-13 20:30:27.385 [vent.ItemStateChangedEvent] - HOME_POWER_COS changed from -14.653048515319824 to -14.535429954528809
2019-10-13 20:30:27.929 [vent.ItemStateChangedEvent] - HOME_POWER_COS changed from -14.535429954528809 to -14.679383277893066

Yes, it is.
Have you tried readValueType="float32_swap" yet, that the link was for?

Yes, I have tried another format. It also provide wrong values

Then maybe your address boundary is wrong. openHAB modbus binding uses register addressing, starting from zero. Many manufacturers data sheets give register numbers, which start from 1.
So far as I can see from your screenshot though, the addressing is correct.

Okay, so your bus monitor shows a return of data bytes
01 04 04 65 43 E0 8E
That will be 16-bit input registers 4 = 6543 and register 5 = E08E
There’s two ways to put those together as a 32-bit float
“ABCD” 6543E08E (OH float32 type) = 5.7812735 E22, quite large number
or
“CDAB” E08E6543 (OH float32_swap type) = -8.208545 E19, quite a large negative number
Neither of those values looks particularly sensible,

If you are expecting around 230 - a voltage perhaps? - then the returned registers must be byte-swapped in the way you did in the screenshot, "BADC`
That is an unusual way to do it, but as I said there are no real rules.
But because it is unusual (I’ve never seen it before) there is no provision for it in the OH Modbus binding.

I think perhaps you will have to fetch the registers as a 32-bit integer and use either a rule or a transform to treat that as bytes, rearrange, and then do IEEE754 convert.
Or fetch as four bytes, and convert in a rule.

This old post has a bytes-to-float rule snippet

1 Like

I found issue. It is not OH issue.
I try to move OH from separate PC to jail in FreeNAS. During this process i want to remove hardware dependency but I use RS485 Modbus in current configuration.
I created custom TCP<=>RS485 converter based on ESP32 and ESP-IDF library. Modbus implementation in this library swap hi and lo bytes. I disabled it and all works ok. I not sure that is good solution, but it works for now.

1 Like

That would be a bit hard to guess.