-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mqtt] Parsing floats with a lowercase "e" separating mantissa and exponent fails #13373
Comments
This issue has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/error-parsing-floats-with-negative-exponent/138746/4 |
From briefly looking at the source code, it seems that the payload is parsed as a DecimalType. |
After debugging, this does not seem to be a bug in MQTT, the root cause is in the Java Number class: It wants a upper case E as the exponent, the Decimal Type extends it so it has the same behavior. |
Thanks @FordPrfkt for looking into this. While I've my own workaround (regex via thing transition) running, your suggestion is probably the best way to go. I'll create a ticket in the main repo and we'll see what the core devs think about it. Again thank you! |
Yes, thats probably for the best. Maybe the current behavior is intentional or changing the DecimalType breaks something else... |
@abbe79 have you opened an issue in the main repo about this? If so could you link it here? |
Hi @jimtng, thanks for the reminder, issue to be found at openhab/openhab-core#3833 |
The related PR to fix this issue was merged in core. It should be included in 4.1.0 milestone 3. |
Hi,
using stable 3.3 I get following entry in my log file when my PV inverter sends really small wattage values at night:
Incoming payload '5.605193857299268e-45' not supported by type 'NumberValue'
Seems like mqtts NumberValue does not like the lowercase "e", separating mantissa and exponent.
Using an uppercase "E" (->
5.605193857299268E-45
) works.While I could work around this using a transformation, I think others could fall in this trap too, because this is the notation that is used by C++ (and probably other languages too), see https://cplusplus.com/reference/ios/scientific/
Could this be changed to accept both notations? Thanks!
Expected Behavior
Float value
5.605193857299268e-45
should be parsed correctly to the "close to zero" value.Using an uppercase E works as intended.
Current Behavior
Parsing fails and item is not updated. Log entry is:
2022-09-08 20:51:01.336 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Incoming payload '5.605193857299268e-45' not supported by type 'NumberValue'
Possible Solution
Accept "e" and "E".
Steps to Reproduce (for Bugs)
Send
5.605193857299268e-45
to an mqtt number channel.Context
My PV inverter sends values in this format, this is the default that C++s std::scientific uses.
Your Environment
The text was updated successfully, but these errors were encountered: