我正在尝试连接到蓝牙设备(Adafruit Flora BLE)并寻找特征数据来附加通知回调。问题是,我没有看到列出的任何特征。我所看到的只是服务本身的属性而没有特征。
以下是一些代码,显示设备标识和查找服务的位置。请原谅意大利面条代码,现在只需调试/黑客攻击原型。
基本上,我正在尝试在arduino / flora模块上为BLE服务设置通知程序,以便我可以通过UART传感器数据发送。我有所有的连接工作,但似乎无法让听众和更新部分工作。谢谢!
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {
let UUID = "818ECB19-BB61-BE95-2D04-64E5D90845EF";
if (peripheral.identifier.UUIDString == UUID){
// print("Peripheral found with name: \(peripheral.name)\nUUID: \(peripheral.identifier.UUIDString)\nRSSI: \(RSSI)\nAdvertisement Data: \(advertisementData)")
visiblePeripheralUUIDs.addObject(peripheral.identifier.UUIDString)
visiblePeripherals[peripheral.identifier.UUIDString] = Peripheral(peripheral: peripheral, RSSI: RSSI.stringValue, advertisementDictionary: advertisementData)
tableView.reloadData()
//
connectedPeripheral = peripheral
connectionAttemptTimer = NSTimer.scheduledTimerWithTimeInterval(10, target: self, selector: Selector("timeoutPeripheralConnectionAttempt"), userInfo: nil, repeats: false)
manager.connectPeripheral(connectedPeripheral!, options: nil)
}
}
func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) {
//print("Peripheral connected: \(peripheral.name ?? peripheral.identifier.UUIDString)")
connectionAttemptTimer?.invalidate()
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let peripheralViewController = storyboard.instantiateViewControllerWithIdentifier("PeripheralViewController") as! PeripheralViewController
peripheralViewController.peripheral = peripheral
navigationController?.pushViewController(peripheralViewController, animated: true)
print("--------Starting service discovery")
// print("!!!!!!!!!!Services be present \(peripheral.services?.count)");
// for service in (peripheral.services)! {
// print("SERVICES: \(service)")
// }
}
func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?) {
print("GOT TO PERIPHERAL")
if (peripheral != self.peripheral) {
// Wrong Peripheral
print("WrONG PERIPHERAL")
return
}
if (error != nil) {
print(" GOTS US AN ERROR")
return
}
print("CHECKING ON CHARACTERISTICS \(service.UUID)")
// for characteristic in service.characteristics! {
// print("CHARACTERISTIC \(characteristic)")
// if characteristic.UUID == service2 {
// print("WHAT THE F*** BRO \(characteristic as CBCharacteristic)");
// peripheral.setNotifyValue(true, forCharacteristic: characteristic as CBCharacteristic)
//
// // Send notification that Bluetooth is connected and all required characteristics are discovered
// //self.sendBTServiceNotificationWithIsBluetoothConnected(true)
// }
// }
}
`func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?) {
print("GOT TO PERIPHERAL")
if (peripheral != self.peripheral) {
// Wrong Peripheral
print("WrONG PERIPHERAL")
return
}
if (error != nil) {
print(" GOTS US AN ERROR")
return
}
print("What is service: \(service)")
for characteristic in service.characteristics! {
print("CHARACTERISTIC \(characteristic)")
if characteristic.UUID == service2 {
print("WHAT THE F*** BRO \(characteristic as CBCharacteristic)");
peripheral.setNotifyValue(true, forCharacteristic: characteristic as CBCharacteristic)
// Send notification that Bluetooth is connected and all required characteristics are discovered
//self.sendBTServiceNotificationWithIsBluetoothConnected(true)
}
}
}
更新了didDiscoverCharacteristicsForService,它仍然没有为我在for循环中解析任何东西:
{{1}}
我在这里错过了一些愚蠢的东西吗?
基督教