-
Notifications
You must be signed in to change notification settings - Fork 32
Fix MQTT message conversion for large numeric values and make character code parsing configurable #551
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: Apollon77 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Please make the whole "parse a comma separated number list into binary data" configurable. Add a configuration option for this. By default it should be disabled.
| // First validate all parts are valid character codes | ||
| for (let p = 0; p < parts.length; p++) { | ||
| str += String.fromCharCode(parseInt(parts[p].trim(), 10)); | ||
| const charCode = parseInt(parts[p].trim(), 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot To prevent double "parseInt" there should be no issue to start to build the strig as long as characters as value but just stop that at the first invalid char. Only when all chars were valid you use the build string. So you prevent duplicate logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimized the implementation to build the string and validate character codes in a single pass. Now only one parseInt call per part is made, and the loop stops immediately at the first invalid character code. The converted string is only used if all parts were valid. (commit 75aeaaa)
… implementation Co-authored-by: Apollon77 <[email protected]>
Added |
The MQTT adapter was incorrectly converting comma-separated numeric data as character codes, causing devices like NUKI 3.0 Pro locks to display garbled values instead of the original data. Based on feedback, the character code parsing feature has been made configurable and is disabled by default.
Problem
When receiving MQTT messages with comma-separated numbers like
"3,0,442236930,1,2", the adapter was automatically attempting to convert these as Unicode character codes. Since442236930exceeds the valid Unicode range, this resulted in corrupted or empty display values in ioBroker objects, while tools like MQTTX showed the correct original values.Root Cause
The
convertMessagefunction inlib/common.jsassumed any string matching the pattern of comma-separated numbers should be converted from character codes to UTF-8 strings, without validating if the numbers were within valid character code ranges.Solution
parseCharCodesconfiguration option in the admin interface to make character code parsing opt-inChanges
Testing
"3,0,442236930,1,2"now correctly remains unchanged in all configurations"65,66,67"only convert to"ABC"when feature is explicitly enabledMigration
Existing installations will have character code parsing disabled by default, ensuring complete backward compatibility and preventing the NUKI issue from occurring. Users can optionally enable the feature in the adapter settings if needed.
Fixes #392.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.