Fix Huawei AH100 body composition parsing #1245
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Huawei AH100 body composition parsing
Summary
This PR fixes the Huawei AH100 (CH100) Bluetooth scale handler to properly parse body composition metrics (body fat %, body water %, and impedance) in addition to weight. Previously, the handler only showed weight measurements.
Problem
The original implementation attempted to parse measurement data after AES-CTR decryption, but the scale actually transmits data that is XOR-obfuscated only (using device MAC address), not AES encrypted. This caused all body composition values to be incorrect or missing.
Solution
Through reverse engineering with BLE packet captures, I discovered the correct data format:
Measurement Data Format
The scale sends measurements as two 16-byte frames (opcodes
0x0Eand0x8E) that are merged into a 32-byte buffer. This data is XOR-obfuscated with the device MAC address but NOT AES encrypted.Byte positions in the XOR'd 32-byte buffer:
weight_kg = (1457 - byte[1]) / 10)Key Changes
handleEncryptedPair()- data is XOR-onlyInteresting Discovery: App-Dependent Calculations
Position 20 shows different values depending on which app is connected:
This suggests the scale performs different calculations based on user profile data sent by each app during the authentication/setup phase.
Testing
Tested with:
Limitations
Timestamp: The exact position of the timestamp in the 32-byte buffer has not been identified. The handler uses the current device time (
Date()) for measurements. This is acceptable for real-time measurements but may affect historical data accuracy.Additional metrics: Other metrics that Huawei Health displays (visceral fat, skeletal muscle mass, bone mineral, protein, etc.) are either:
Initial investigation found visceral fat at position 10, but values were inconsistent with scale display and were removed.
Reverse Engineering Process
The fix was developed through systematic BLE packet analysis:
Files Changed
android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales/HuaweiAH100Handler.ktparseAndPublishMeasurement()with correct parsing (lines 329-371)u16be()helper for big-endian reads (lines 436-437)BODY_COMPOSITIONcapability (line 74)Commit History
85bf57c8- Fix Huawei AH100 body composition parsing (remove AES, fix weight/impedance)70f8fe4e- Add visceral fat, skeletal muscle, and body water parsing9b28fb84- Parse position 20 as body fat percentage2bc88406- Remove visceral fat parsing due to inaccurate valuesRelated Issues
This addresses users who reported that the Huawei AH100 scale only showed weight without body composition metrics when using openScale, while the official Huawei Health app displayed full body composition data.