You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS Swift应用中如何从AND BLE体重秤UUID:2A9D获取正确测量值

Hey there! Let's get that weight parsing sorted out—your issue looks like a common combination of byte order mismatch and missing unit conversion, which is super typical with BLE devices.

First, let's break down the numbers: you're seeing 11860.0 when the actual weight is 59.2kg. If you do the math, 11860 × 0.005 = 59.3kg, which is almost exactly your measured value (likely just a tiny measurement error). That tells me the raw integer from the BLE data uses a scaling factor of 0.005kg per unit, and you're probably just displaying the raw integer without applying this conversion.

On top of that, BLE devices almost always send multi-byte values in little-endian order, so we need to make sure we're parsing the bytes correctly.

Here's a step-by-step fix for your Swift code:

1. Extract the weight bytes from the 10-byte data

The A&D UC-352BLE stores weight in the first 2 bytes of the 2A9D characteristic data. We'll pull those out first.

2. Parse the bytes with the correct endianness

Convert the raw bytes to a 16-bit integer, making sure to use little-endian (the standard for BLE).

3. Apply the scaling factor

Multiply the raw integer by 0.005 to get the actual weight in kilograms.

Here's the concrete Swift code:

// Assume this is the 10-byte Data you received from the BLE characteristic
let bleMeasurementData: Data = ... 

// Step 1: Extract the first 2 bytes (weight data)
guard bleMeasurementData.count >= 2 else {
    print("Insufficient data received from scale")
    return
}
let weightBytes = bleMeasurementData.subdata(in: 0..<2)

// Step 2: Parse to 16-bit integer with little-endian order
var rawWeightValue: Int16 = 0
weightBytes.withUnsafeBytes { buffer in
    rawWeightValue = buffer.load(as: Int16.self).littleEndian
}

// Step 3: Convert to actual kg using the scaling factor
let actualWeightKg = Double(rawWeightValue) * 0.005
print("Actual weight: \(actualWeightKg) kg") // Should show ~59.2kg

If you want to confirm the exact byte values, you can print the raw data in hex to cross-verify:

let hexString = bleMeasurementData.map { String(format: "%02X", $0) }.joined()
print("Raw BLE data (hex): \(hexString)")

For a 59.2kg measurement, the first two hex bytes should be 30 2E (which is 11840 in decimal, 11840 × 0.005 = 59.2).

Quick check for common mistakes

  • Did you forget to apply the scaling factor? That's the most likely reason you're seeing 11860 instead of 59.2.
  • Are you using the correct endianness? If you skip .littleEndian, you might get a completely wrong number (e.g., big-endian would interpret 30 2E as 12334 instead of 11840).

Give this a shot, and it should fix your parsing issue!

内容的提问来源于stack exchange,提问作者Uzzal Biswas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:46:03