L2CAP Channel data transfer

本秂侑毒 提交于 2019-12-05 02:14:31

问题


I am working on developing BLE app using connection oriented channel . I am using nordic semiconductor nrf52 as a peripheral device and iPhone 6 as central manager.

I have used predefined PSM value provided by Bluetooth SIG that is 0x0025. I am ble to connect to peripheral and open L2CAP channel successfully.

I am getting below error :

**[CoreBluetooth] WARNING: Unknown error: 436

2018-06-08 10:03:17.532709-0400 BluetoothTest[407:62057] [CoreBluetooth] **No known channel matching peer with psm 37****

Could please let me know how to proceed and what is meaning of error code 436

Below is my code :

   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.
    }

}

回答1:


0x25 PSM is for OTS. You need ATT PSM which is 0x1F




回答2:


I had a similar problem. I manage to solve it by creating a variable to save "channel: CBL2CAPChannel?" in the function

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

I was only saving the "channel.outputStream", which was the only one I needed. But it looks like if you don't save it, it will be closed.



来源:https://stackoverflow.com/questions/50840365/l2cap-channel-data-transfer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!