我正在使用arduino羽毛BLE板並嘗試創建可通過BLE將數據發送到主板的iOS應用。我可以連接,但我不能給txCharacteristiciOS藍牙低功耗(BLE)未發現TX特性
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
guard let characteristics = service.characteristics else {
return
}
for characteristic in characteristics {
if characteristic.properties.contains(.write) || characteristic.properties.contains(.writeWithoutResponse) {
writableCharacteristic = characteristic
}
// if(characteristic.uuid == CBUUID(string: "6e400002-b5a3-f393-e0a9-e50e24dcca9e"))
// {
// txCharacteristic = characteristic
// }
var txUUID = CBUUID(string: "6e400002-b5a3-f393-e0a9-e50e24dcca9e")
let temp = characteristic.uuid.uuidString;
switch characteristic.uuid {
case txUUID:
txCharacteristic = characteristic;
break;
default:
break;
}
peripheral.setNotifyValue(true, for: characteristic)
}
}
此代碼的工作訪問,但只發現下面的UUID:
temp String "00001532-1212-EFDE-1523-785FEABCD123"
temp String "00001531-1212-EFDE-1523-785FEABCD123"
temp String "00001534-1212-EFDE-1523-785FEABCD123"
我已經想通了,這些UUID的是DFU的UUID。我如何才能發現txCharacteristic?
增加了對更多信息如何,我打電話discoverCharacteristics():
extension SimpleBluetoothIO: CBPeripheralDelegate {
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
guard let services = peripheral.services else {
return
}
targetService = services.first
if let service = services.first {
targetService = service
peripheral.discoverCharacteristics(nil, for: service)
}
}
你確定這是正確的服務在正確的設備上?你用正確的參數調用了「discoverServices」和「discoverCharacteristics」嗎?嘗試下載BLE瀏覽器並檢查它看到的內容。 – Kevin
嗨,謝謝你的幫助。我打電話discoverServices(無)應該發現所有的服務。我已經添加了調用discoverCharacteristics()到上面的問題的代碼。 – Megan