【发布时间】:2019-10-28 22:24:38
【问题描述】:
我有一个在 BLE v4.1 上运行的定制 BLE 设备,我正在使用 swift 5 制作一个 iOS 应用程序,该应用程序能够连接到 iOS 手机范围内的所有 BLE 设备。
我能够连接并显示所有设备(具有特定名称),并在表格中显示它们。另一方面,我有完整的实现,用于连接到第一个发现的 BLE 设备,发现服务,发现特征,使用 BTService 中的 didUpdateValueFor 委托方法读取特征值。
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
NSLog("didUpdateValue function called from BTService")
if error != nil {
print("ERROR ON UPDATING VALUE FOR CHARACTERISTIC: \(characteristic) - \(String(describing: error?.localizedDescription))")
return
}
print("updating value of peripheral \(String(describing: peripheral))")
print("Value of characteristic updated and didUpdateValueFor called. Value of characteristic is: \(characteristic.value!)")
DispatchQueue.main.async(execute: { () -> Void in
self.didReceiveData(characteristic.uuid, characteristic.value!)
if characteristic == OTAUpgradeCharacteristic {
NSLog("Value updated for bootloader characteristic")
bootloaderModel.peripheralValueUpdate(peripheral, characteristic: characteristic, error: error)
}
})
}
我想同时读取多个已连接的同类 BLE 设备中的特性值。我连接的所有 BLE 设备都具有相同的广告名称和相同的特征,但标识符不同。每个设备可能会发送不同的特征值。每次我尝试同时从多个连接的 BLE 设备读取通知数据时,我的代码只会从最后一个连接的设备读取数据。
是否有任何类型的库或代码可用于同时从所有设备获取广告数据,或者为每个连接的外围设备调用 didUpdateValueFor?
【问题讨论】:
标签: bluetooth-lowenergy core-bluetooth swift5