Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 16, 2025

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. Since 442236930 exceeds 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 convertMessage function in lib/common.js assumed 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

  • Added parseCharCodes configuration option in the admin interface to make character code parsing opt-in
  • Disabled by default to ensure existing installations are not affected and NUKI devices work correctly
  • Added validation to ensure character codes are within the extended ASCII range (0-255) before attempting conversion
  • Optimized implementation to avoid duplicate parseInt calls with single-pass validation
  • Added early return after successful character code conversion to prevent further processing
  • Invalid character codes now preserve the original comma-separated string

Changes

  • Added configuration option: New "Parse comma-separated numbers as character codes" checkbox in admin interface
  • Enhanced character code validation: Only values 0-255 are converted as character codes when feature is enabled
  • Performance optimization: Single-pass validation and conversion to avoid duplicate parseInt calls
  • Preserved backward compatibility: Existing installations have the feature disabled by default
  • Added translations: English and German translations for the new configuration option
  • Added comprehensive tests: Covers both enabled/disabled configurations, NUKI data, edge cases, and regression prevention

Testing

  • NUKI data "3,0,442236930,1,2" now correctly remains unchanged in all configurations
  • Valid character codes like "65,66,67" only convert to "ABC" when feature is explicitly enabled
  • All existing tests pass (42/42)
  • New test cases prevent future regressions and validate configuration behavior

Migration

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.

Copilot AI changed the title [WIP] wrong value displayed Fix MQTT message conversion for large numeric values in comma-separated data Sep 16, 2025
Copilot AI requested a review from Apollon77 September 16, 2025 07:46
Copy link
Contributor

@Apollon77 Apollon77 left a 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);
Copy link
Contributor

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

Copy link
Contributor Author

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)

Copy link
Contributor Author

Copilot AI commented Sep 16, 2025

@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.

Added parseCharCodes configuration option in the admin interface. The feature is now disabled by default to ensure existing installations aren't affected. Users can enable it via the "Parse comma-separated numbers as character codes" checkbox in the adapter settings. (commit 75aeaaa)

Copilot AI changed the title Fix MQTT message conversion for large numeric values in comma-separated data Fix MQTT message conversion for large numeric values and make character code parsing configurable Sep 16, 2025
Copilot AI requested a review from Apollon77 September 16, 2025 09:47
Copilot finished work on behalf of Apollon77 September 16, 2025 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wrong value displayed

2 participants