我一直在努力通过CoreBluetooth支持我的应用程序中的欧姆龙血压监视器。使用有关BPM的蓝牙SIG文档(https://www.bluetooth.com/specifications/specs/,然后是BLP和BLS),我可以与监视器连接。
我使用了以下特性:
2A35
BLS文档中的第10页指出,血压测量是属性指示的,据我所知,该属性的行为类似于Notify属性。
为了澄清一些代码,我调用了CBPeripheralDelegate的委托方法
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
print("connected!")
bloodPressurePeripheral.discoverServices([bloodPressureService])
}
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
guard let services = peripheral.services else { return }
services.forEach { service in
print("discovered service: \(service) \n")
peripheral.discoverCharacteristics(nil, for: service)
}
}在didDiscoverCharacteristicsFor函数中,我简单地循环了特征并检查它们的属性。
if char.properties.contains(.read) {
print("\(char.uuid): properties contains .read")
peripheral.readValue(for: char)
}
if char.properties.contains(.indicate) {
print("\(char.uuid): properties contains .indicate")
peripheral.setNotifyValue(true, for: char)
}
if char.properties.contains(.notify) {
print("\(char.uuid): properties contains .notify")
peripheral.setNotifyValue(false, for: char)我尝试了readValue和setNotifyValue,以表明我仍然得到了以下结果:
<CBCharacteristic: 0x2829880c0, UUID = 2A35, properties = 0x20, value = (null), notifying = NO>
2A35: properties contains .indicate
<CBCharacteristic: 0x282988180, UUID = 2A49, properties = 0x2, value = {length = 2, bytes = 0x2700}, notifying = NO>
2A49: properties contains .read我真的不明白2A35的值为什么是空的。我知道有一些值,因为使用欧姆龙应用程序,我可以得到测量值。
我的实际问题是:有没有人在使用CoreBluetooth连接(欧姆龙)BPM方面有任何经验,我忽略了什么?
谢谢你的回答!
发布于 2022-11-15 06:04:05
我试过把Ormon和Android设备连接起来。我会告诉你我从中学到了什么。
注:- Ble设备异步通信,您必须一次执行GATT操作(例如,读、写、启用通知、启用指示)。下一次操作只能在成功完成上一次操作之后才能完成。
我的设备有以下服务。
关贸总协定在成功连接后的第一个操作是gatt.discoverServices()。(事件onServicesDiscoverd被触发,在android中)
如果您只需要没有读取状态和时间戳的BP读数,只需启用UUID 2A35的指示即可。
val bloodPressureService = gatt?.getService(BLOOD_PRESSURE_SERVICE_UUID)
val bloodPressureChar = bloodPressureService?.getCharacteristic(BLOOD_PRESSURE_CHAR_UUID)
gatt?.setCharacteristicNotification(bloodPressureChar, true)
val bloodDescriptor = bloodPressureChar?.getDescriptor(CCC_DESCRIPTOR_UUID)
bloodDescriptor?.value = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE
gatt?.writeDescriptor(bloodDescriptor)https://stackoverflow.com/questions/68496497
复制相似问题