3

我正在使用面向连接的通道开发 BLE 应用程序。我使用北欧半导体 nrf52 作为外围设备和 iPhone 6 作为中央管理器。

我使用了蓝牙 SIG 提供的预定义 PSM 值,即 0x0025。我能够连接到外围设备并成功打开 L2CAP 通道。

我收到以下错误:

**[CoreBluetooth] 警告:未知错误:436

2018-06-08 10:03:17.532709-0400 BluetoothTest[407:62057] [CoreBluetooth] **没有已知的通道匹配对等体与 psm 37****

请让我知道如何进行以及错误代码 436 的含义

下面是我的代码:

   func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
        //handling callback when a peripheral is discover
        print("Central Manager PowerOn State Check:\(central.state.rawValue)")
        if (peripheral.name?.contains("Nordic_OTSX") == true)
       {
            print(peripheral.name ??  "no name")
            print("advertisement Data : \(advertisementData) ")
            central.connect(peripheral, options: nil )
            myPeripheral = peripheral
       }
    }


    func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral)
    {
        print("didConnect\(myPeripheral.debugDescription)")
        myPeripheral.delegate = self
        myPeripheral.discoverServices(nil)
    }
    //if error while making connection
    func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?)
    {
        print("error:\(error.debugDescription)")
    }

    //after opening L2CAP Channel
   func peripheral(_ peripheral: CBPeripheral, didOpen channel: CBL2CAPChannel?, error: Error?)
    {
        print("didOpen")
        print(error.customMirror)
        print(channel!.outputStream.debugDescription)
        print(channel!.inputStream.debugDescription)
        print(channel?.outputStream.hasSpaceAvailable)
    }


    func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?)
    {
        print("*******************************************************")

        if ((error) != nil) {
            print("Error discovering services: \(error!.localizedDescription)")
            return
        }

        guard let services = peripheral.services else {
            return
        }
        //We need to discover the all characteristic
        for service in services {

            peripheral.discoverCharacteristics(nil, for: service)
            // bleService = service
        }
        print("Discovered Services: \(services)")
    }


    func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)
    {
        print("*******************************************************")
        if let charcterstics = service.characteristics
        {
            print("characteristics :")
            for char in charcterstics
            {
               /* if char.uuid == buttonCharacteristicUUID
                {
                    buttonCharacteristic = char
                    enableButtonNotifications(buttonCharacteristic!)
                    readButtonValue()
                }*/
                print(char.uuid.uuidString)
            }
        }
         peripheral.openL2CAPChannel(0x0025)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
4

2 回答 2

3

我有一个类似的问题。我设法通过创建一个变量来channel: CBL2CAPChannel?在函数中保存“”来解决它

func peripheral(_ peripheral: CBPeripheral, didOpen channel: CBL2CAPChannel?, error: Error?)

我只保存了“ channel.outputStream”,这是我唯一需要的。但看起来如果你不保存它,它将被关闭。

于 2018-09-08T22:42:53.300 回答
2

0x25 PSM 用于OTS。您需要 ATT PSM,即 0x1F

于 2018-06-14T10:49:01.787 回答