Repository navigation
Description
Preflight Check (Required)
- I tested the latest dev version https://github.com/oliexdev/openScale/releases/tag/dev-build
- The issue still occurs in the dev version
- I searched the existing open and closed issues
- This issue has not already been reported or fixed
Bug Description
As other has reported, the Huawei CH100 scale, or off measurements on both weight and body-fat.
This is not mere a bugreport, but also include a workable "patch". I prefer this to a pull request, as my code right now is filled up with a lot of lovely debug information :-)
Anyway, what I have done is revert the incorrect measurement parsing changes from commit 2e7e708 that
caused wrong weight and body fat calculations.
Issues fixed:
- Weight was using incorrect formula: (1457 - byte[1]) / 10
- Body fat was reading from wrong position (20) as whole percent
- Data was being treated as XOR-only instead of AES-CTR encrypted
- CH100 device name was not recognized (CH100 is same hardware as AH100)
The December 2025 commit was based on incorrect reverse engineering, I assume. My scale data is AES-CTR encrypted (not just XOR obfuscated) and uses the original v2.5.4 format.
Restored correct parsing:
- User ID: position 0
- Weight: positions 1-2 (little-endian 16-bit, divided by 10)
- Body fat: positions 3-4 (little-endian 16-bit, divided by 10)
- Timestamp: positions 5-12 (year, month, day, hour, minute, second)
- Resistance: positions 13-14 (for future body composition calculations)
Added CH100 device name support since CH100 and AH100 are the same
hardware with different advertised names.
I will put the patch in the "how-to-recreated" session.. /JPH
Steps to Reproduce
---
.../bluetooth/scales/HuaweiAH100Handler.kt | 89 +++++++++++--------
1 file changed, 52 insertions(+), 37 deletions(-)
diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales/HuaweiAH100Handler.kt b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales/HuaweiAH100Handler.kt
index f14abe4d..8c9e3f12 100644
--- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales/HuaweiAH100Handler.kt
+++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales/HuaweiAH100Handler.kt
@@ -36,7 +36,7 @@ import javax.crypto.spec.SecretKeySpec
import kotlin.math.min
/**
- * Driver for Huawei AH100 body fat scale (BLE).
+ * Driver for Huawei AH100 / CH100 body fat scale (BLE).
*
* Protocol: Custom GATT-based with AES-CTR encryption and XOR obfuscation.
* - Service: 0xFAA0
@@ -65,7 +65,7 @@ class HuaweiAH100Handler : ScaleDeviceHandler() {
}
override fun supportFor(name: String): SupportLevel {
- if (name != "AH100") return null
+ if (name != "AH100" && name != "CH100") return null
val all = setOf(
DeviceCapability.USER_SYNC,
DeviceCapability.TIME_SYNC,
@@ -71,7 +71,7 @@ class HuaweiAH100Handler : ScaleDeviceHandler() {
DeviceCapability.HISTORY_READ
)
val implemented = setOf(
- DeviceCapability.BODY_COMPOSITION, // Weight, fat%, and impedance
+ // DeviceCapability.BODY_COMPOSITION, // TODO only fat
DeviceCapability.TIME_SYNC,
DeviceCapability.USER_SYNC,
// We parse history frames; triggering full history pull is partial here.
@@ -296,14 +296,20 @@ class HuaweiAH100Handler : ScaleDeviceHandler() {
val p2 = payload(second)
val merged = concat(p1, p2)
- logD("XOR'd data (${merged.size}b): ${hex(merged, 0, min(merged.size, 32))}${if (merged.size>32) " …" else ""}")
+ val key = magicKey ?: return logW("magicKey missing; drop frame")
+ val plain = try {
+ aesCtr(merged, key, initialIv)
+ } catch (e: GeneralSecurityException) {
+ logW("AES decrypt failed: ${e.message}")
+ return
+ }
+
+ logD("Decrypted (${plain.size}b): ${hex(plain, 0, min(plain.size, 32))}${if (plain.size>32) " …" else ""}")
- // Data is XOR-obfuscated only, NOT AES encrypted
- // Parse directly from the XOR'd data
when (type) {
- NTFY_MEASUREMENT -> parseAndPublishMeasurement(merged)
+ NTFY_MEASUREMENT -> parseAndPublishMeasurement(plain)
NTFY_HISTORY_RECORD -> {
- parseAndPublishMeasurement(merged)
+ parseAndPublishMeasurement(plain)
// Then request next; scale will stop with HISTORY_UPLOAD_DONE
sendGetHistoryNext()
}
@@ -311,52 +317,61 @@ class HuaweiAH100Handler : ScaleDeviceHandler() {
}
/**
- * Measurement format (XOR-obfuscated, 32 bytes merged from two 16-byte frames):
- *
- * Based on reverse engineering - data is XOR obfuscated only, NOT AES encrypted:
- * - Position 1: Weight (encoded as: weight_kg = (1457 - byte[1]) / 10)
- * - Position 2-3: Impedance (big-endian, ohms)
- * - Position 20: Body fat % (whole percent)
- * - Position 27: Body water % (whole percent)
- * - Position 31: User ID
- * - Timestamp: Position not yet identified (using current time)
- *
- * Note: Position 20 shows different values depending on the connected app:
- * - With openScale: displays as body fat %
- * - With Huawei Health: displays as skeletal muscle %
- * The scale likely calculates differently based on user profile data sent by each app.
+ * Decrypted measurement format (derived from v2.5.4):
+ * index:
+ * 0 : userId
+ * 1..2 : weight tenth-kg LE
+ * 3..4 : fat (x10) LE
+ * 5..6 : year LE
+ * 7 : month (1..12) -> convert to 0-based for Calendar
+ * 8 : day
+ * 9 : hour
+ * 10 : minute
+ * 11 : second
+ * 12 : weekday (unused)
+ * 13..14: resistance LE
*/
private fun parseAndPublishMeasurement(data: ByteArray) {
- if (data.size < 32) {
- logW("Measurement data too short: ${data.size} bytes")
- return
- }
-
- // Weight at position 1, encoded formula
- val weightByte = data[1].toInt() and 0xFF
- val weight = (1457 - weightByte) / 10.0f
-
- // Impedance at position 2-3, big-endian, ohms
- val impedance = u16be(data, 2)
-
- // Body fat % at position 20
- val fat = (data[20].toInt() and 0xFF).toFloat()
-
- // Body water % at position 27
- val water = (data[27].toInt() and 0xFF).toFloat()
+ if (data.size < 15) return
- // User ID at position 31
- val userId = data[31].toInt() and 0xFF
+ val userId = data[0].toInt() and 0xFF
+ val weightTenth = u16le(data, 1)
+ val weight = weightTenth / 10.0f
+ val fat = u16le(data, 3) / 10.0f
+ val year = u16le(data, 5)
+ val month1 = (data[7].toInt() and 0xFF).coerceIn(1, 12)
+ val day = data[8].toInt() and 0xFF
+ val hour = data[9].toInt() and 0xFF
+ val minute = data[10].toInt() and 0xFF
+ val second = data[11].toInt() and 0xFF
+ val resistance = u16le(data, 13)
- // Use current time since timestamp position not yet identified
- val dt = Date()
+ // Build date
+ val cal = Calendar.getInstance().apply { set(year, month1 - 1, day, hour, minute, second) }
+ val dt = cal.time
- lastMeasuredWeightTenthKg = (weight * 10).toInt()
+ lastMeasuredWeightTenthKg = weightTenth
val m = ScaleMeasurement().apply {
this.userId = userId
this.dateTime = dt
this.weight = weight
this.fat = fat
- this.water = water
- if (impedance > 0 && impedance < 4000) {
- this.impedance = impedance.toDouble()
- }
+ // TODO: if someone contributes formulas, fill water/muscle/bone via resistance.
}
publish(m)
- logI("Measurement: ${weight} kg, fat=${fat}%, water=${water}%, impedance=${impedance} Ω, userId=$userId @ ${ts(dt)}")
+ logI("Saved @ ${ts(dt)} kg=$weight fat=$fat% R=$resistance")
- // Acknowledge measurement
+ // Acknowledge composition if already bound; harmless otherwise
sendCmd(CMD_FAT_RESULT_ACK, byteArrayOf(0x00))
}
--
2.48.1
Debug Log (Required)
Not applicable.
Activity
oliexdev commentedon Jan 7, 2026
it seems like that the CH100 use aes and the AH100 xor? As @martinriedel send the follwing #1245
I don't own these scales but would be better to seperate the handling of these two scales?
Could you do that and send a PR?
oliexdev commentedon Jan 7, 2026
That would be great. I’ll close this issue for now — please send a PR once you’ve finished.
syyyr commentedon Feb 9, 2026
Looks like this account is deleted, so no one is working on anything. I tried applying the patch in this issue, but it doesn't apply cleanly (or at least not on current master). I tried applying it manually, but I still get the massively large values. I'll try looking into this when I have the time.
Btw, there's now no open tracking issue for this bug.
syyyr commentedon Feb 13, 2026
I tried using this 67fa05d as a base, because of the database changes and just reverting the AH100 changes, which revert cleanly, but unfortunately I still get the large values. I guess something must have happened with the format of the data or the database?
Fix Huawei AH100 / CH100 measurement parsing (closes #1206, #1280) (#…