I have a Modbus energy meter connected to my energy storage system and I’d like to read the values in OpenHAB. I was polling it with the Modbus binding but having two clients trying to poll the same meter was causing issues with the inverter.
I have worked out a way to eavesdrop the exchanges between the inverter and the meter and I’m successfully getting byte streams into an OpenHAB item but I can’t work out how to convert the data, which is encoded as a float32 into a readable form.
Can anyone help with a rule syntax to convert a four byte string into a float32 number please?
The string is exactly like your example. A sequence of 4 x 8 bit values.
The background is that the meter is connected to the inverter by two devices, each converting Modbus serial into a Modbus TCP packet that is transmitted over Ethernet or vice versa.
The conversion devices also have the capability to take the serial messages and turn them into an HTTP message. I use this function to transmit each serial message to OpenHAB, which receives them as a string. I then substring out the four bytes that represent the meter register value in 32 bit float. I need to convert them into a suitable Number type to use in OpenHAB.
Doesn’t parseInt take text characters representing digits and turn them into a Number as you might need to when parsing a JSON response?
I need to take an IEEE 754 32 bit float value, arriving as 4 x 8 bit bytes and turn that into a decimal number. I would provide an example but the string usually contains unprintables because they are just bytes.
In your example above, my string would be:
“BEL i HT o” assumig A9 is the same as 09 when we are writing it out.
By way of another example, if my string was “1234”, that would be Hex 31 32 33 34 and convert to floating pioint number: 0.00000000259315147133065693196840584278106689453125
String “CDEF” converts to 43 44 45 46 and into floating point 196.270599365234375