[英]How to get data from body scale as CBPeripheral using BLE (Bluetooth Low Energy) on iOS
I just started using Bluetooth and want to read the body composition measurement from a body scale (Model: adeVital Analysis BA 1401) via Bluetooth. 我刚开始使用蓝牙,想通过蓝牙从体重秤(型号:adeVital Analysis BA 1401)读取身体成分测量值。
When set up my iPhone as Central and connect it to the scale (which is CBPeripheral), I can read the scales device information such as Hardware Revision Number, Manufacturer, etc. I can't get the actual measurement data though. 将iPhone设置为Central并将其连接到电子秤(即CBPeripheral)时,我可以读取电子秤的设备信息,例如硬件修订号,制造商等。但是我无法获得实际的测量数据。
I iterated through all services and characteristics and set the notification flag. 我遍历了所有服务和特性并设置了通知标志。
[peripheral setNotifyValue:YES forCharacteristic:aCharacteristic]
for each characteristic. 对于每个特征。 And the delegate method
和委托方法
- (void) peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
gets called without error. 被正确调用。 When I check the updated peripheral, I find this:
当我检查更新的外围设备时,我发现:
<CBCharacteristic: 0x1740949b0, UUID = 8A82, properties = 0x20, value = <a1014711 f3000000 00000000 00000000 00000000>, notifying = YES>
This all happens when the scale is turned on (without having measured anything yet). 这一切都在秤打开时发生(尚未测量任何东西)。 Now when I step on the scale and the measurement is done, it shows a Bluetooth icon indicating a data transfer, the iOS Application is not receiving any notifications though.
现在,当我踩秤并完成测量时,它会显示一个蓝牙图标,指示数据传输,但是iOS应用程序未收到任何通知。 What am I missing?
我想念什么?
So summarized: The peripheral connects to the central and updates a characteristic before it measures, but after that, no more notifications come up. 总结如下:外设连接到中央并在测量之前更新特性,但是此后,不再发出通知。
Could the value in the updated CBCharacteristic be a UUID for a Service to which I would have to subscribe somehow to get the actual data? 更新后的CBCharacteristic中的值是否可以是我必须以某种方式订阅以获取实际数据的服务的UUID?
Hope someone can help me out here 希望有人可以帮助我
EDIT: 编辑:
As it might be relevant, here are the services and characteristics I receive: 可能相关,以下是我收到的服务和特性:
Services:
"<CBService: 0x17407dc40, isPrimary = YES, UUID = Device Information>",
"<CBService: 0x174070f80, isPrimary = YES, UUID = 7802>"
Characteristics
"<CBCharacteristic: 0x1740959a0, UUID = Serial Number String, properties = 0x2, value = (null), notifying = NO>",
"<CBCharacteristic: 0x174095900, UUID = Hardware Revision String, properties = 0x2, value = (null), notifying = NO>",
"<CBCharacteristic: 0x1740952c0, UUID = Firmware Revision String, properties = 0x2, value = (null), notifying = NO>",
"<CBCharacteristic: 0x1740958b0, UUID = Manufacturer Name String, properties = 0x2, value = (null), notifying = NO>",
"<CBCharacteristic: 0x174095860, UUID = Software Revision String, properties = 0x2, value = (null), notifying = NO>"
"<CBCharacteristic: 0x170095ea0, UUID = 8A21, properties = 0x20, value = (null), notifying = NO>",
"<CBCharacteristic: 0x170095e50, UUID = 8A22, properties = 0x20, value = (null), notifying = NO>",
"<CBCharacteristic: 0x1700952c0, UUID = 8A20, properties = 0x2, value = (null), notifying = NO>",
"<CBCharacteristic: 0x170095e00, UUID = 8A81, properties = 0x8, value = (null), notifying = NO>",
"<CBCharacteristic: 0x170095db0, UUID = 8A82, properties = 0x20, value = (null), notifying = NO>"
EDIT 2: 编辑2:
The CBCharacteristics have the following properties: CBCharacteristics具有以下属性:
8A20 = Read
8A21 = Indicate
8A22 = Indicate
8A81 = Write
8A82 = Indicate
all other properties are BOOL NO 所有其他属性均为BOOL NO
When I turn on notifications for 8A21, 8A22 and 8A82, I receive an NSData from 8A82 right at the start, when the scale is turned on (so it can't be a measurement at that point). 当我打开有关8A21、8A22和8A82的通知时,我一开始就从8A82收到了一个NSData,打开了比例尺(因此该点不能作为测量值)。 I assume, the actual measurement data is being updated by the 8A21 characteristic.
我假设实际测量数据正在通过8A21特性进行更新。 Yet it won't notify my delegate and I can't figure out why.
但是它不会通知我的代表,我也不知道为什么。
Viewing the syslog, you can see that the official app of the manufacturer spills the log as follows: 查看系统日志,您可以看到制造商的官方应用程序将日志溢出,如下所示:
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = receive push data(<a1018b3b 02000000 00000000 00000000 00000000>),with command(a1), from characteristic(8A82)
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = receive randomnumber (37456641)
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = next step is :operating_receive_random_number
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = next step is :operating_write_xor_results
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write command with data:<200eff57 c5>
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write command data((null)) to characteristic(8A81)
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write success with status - operating_write_xor_results
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = next step is :operating_write_utc_time
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write command with data:<02033b8b 0b>
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write command data((null)) to characteristic(8A81)
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write success with status - operating_write_utc_time
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = next step is :operating_write_disconnect
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write command with data:<22>
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write command data((null)) to characteristic(8A81)
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = write success with status - operating_write_disconnect
Feb 20 14:19:49 i6S lifesensehealth1_1[4163]: message = next step is :operating_uploaded_results_process
You need to write some data to a certain characteristic first. 您需要首先将某些数据写入特定的特征。 In my case that characteristic was
8A81
. 在我的情况下,该特性是
8A81
I wrote a byte array of a UTC Time code I generated through an algorithm that I cannot publish here. 我编写了一个UTC时间代码的字节数组,该代码是通过无法在此处发布的算法生成的。 Try writing any 5-byte long array/char to it and see what happens (For example:
[1,1,1,1,1]
) 尝试向其中写入任何5字节长的数组/字符,看看会发生什么(例如:
[1,1,1,1,1]
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.