问题描述
iPad(中央)的HCI日志:
nRF Connect日志:
我的Mac(外围设备)出现HCI日志错误之一:
我正在尝试从Mac播发CoreBluetooth HID外围设备,并将其连接到另一台设备。广告效果很好,我可以在iPad设置的“蓝牙”部分下看到“外围设备”。但是,当我尝试从iPad连接到我的外围设备时,它显示已连接,但15秒钟后它立即断开连接。这是我到目前为止的代码:
import AppKit
import PlaygroundSupport
import CoreBluetooth
//Service UUID Declarations
let HIDServiceUUID = CBUUID(string:"1812")//1812 is the 16-bit identifier for BLE's HIDService
let BatteryServiceUUID = CBUUID(string:"180F")
let Device@R_50_4045@ionUUID = CBUUID(string:"180A")
let HIDproperties: CBCharacteristicProperties = [.notify,.read,.writeWithoutResponse]
let deviceInfoProperties: CBCharacteristicProperties = [.read]
let permissions: CBAttributePermissions = [.readable]
let nopermissions: CBAttributePermissions = []
//HID Service characteristics
//Boot Mouse Input Report
let HIDBootMouseProperties:CBCharacteristicProperties = [.read,.write,.notify]
let HIDBootMouse = CBMutableCharacteristic(type:CBUUID(string: "2A33"),properties: HIDBootMouseProperties,value:nil,permissions: nopermissions)
//HID Control Point Characteristic
let HIDCPProperties:CBCharacteristicProperties = [.writeWithoutResponse]
let HIDControlPoint = CBMutableCharacteristic(type:CBUUID(string: "2A4C"),properties: HIDCPProperties,permissions: nopermissions)
//HID @R_50_4045@ion Characteristic
let HID@R_50_4045@ionProperties: CBCharacteristicProperties = [.read]
let HID@R_50_4045@ion = CBMutableCharacteristic(type:CBUUID(string: "2A4A"),properties: HID@R_50_4045@ionProperties,permissions: nopermissions)
//Device @R_50_4045@ion Service
let DeviceNameCharacteristic = CBMutableCharacteristic(type:CBUUID(string: "2A00"),properties: deviceInfoProperties,value:Data(base64Encoded: "hello"),permissions: permissions)
let DevicePnP = CBMutableCharacteristic(type:CBUUID(string: "2A50"),value:Data(base64Encoded: "BUT"),permissions: permissions)
let DeviceSerialCharacteristic = CBMutableCharacteristic(type:CBUUID(string: "2A25"),value:Data(base64Encoded: "2F93"),permissions: permissions)
//Battery Service characteristics
let batteryProperties: CBCharacteristicProperties = [.read]
let batteryCharacteristic = CBMutableCharacteristic(type:CBUUID(string: "2A19"),properties: batteryProperties,value:Data (_:[0x60]),permissions: permissions)
//let myGATTService = CBMutableService(type:GATTServiceUUID,primary: false)
//Initialize Services
let myHIDService = CBMutableService(type:HIDServiceUUID,primary: true)
let myBatteryService = CBMutableService(type:BatteryServiceUUID,primary: true)
let mydiservice = CBMutableService(type:Device@R_50_4045@ionUUID,primary: true)
myHIDService.characteristics = [HIDControlPoint,HID@R_50_4045@ion,HIDBootMouse]
myBatteryService.characteristics = [batteryCharacteristic]
mydiservice.characteristics = [DeviceNameCharacteristic,DeviceSerialCharacteristic,DevicePnP]
class Peripheral: NSObject,CBPeripheralManagerDelegate
{
var peripheralManager : CBPeripheralManager!
override init(){
print("Manager Initialized!")
super.init()
peripheralManager = CBPeripheralManager(delegate: self,queue: nil)
}
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager)
{
print("State updated!")
if (peripheral.state == .poweredOn)
{
peripheralManager.publishL2CAPChannel(withEncryption: true)
peripheralManager.add(myHIDService)
peripheralManager.add(myBatteryService)
peripheralManager.add(mydiservice)
let advertisementData = [CBAdvertisementDataLocalNameKey: ["BLE Test"],CBAdvertisementDataServiceUUIDsKey: [HIDServiceUUID]] as [String: Any]
peripheralManager.startAdvertising(advertisementData)
//print("state: \(peripheral.state)")
}
}
func peripheralManagerIsReady(toUpdateSubscribers peripheral: CBPeripheralManager) {
print("ready1!!")
}
func peripheralManager(_ peripheral: CBPeripheralManager,didOpen channel: CBL2CAPChannel?,error: Error?) {
print("opened")
}
func peripheralManager(_ peripheral: CBPeripheralManager,didPublishL2CAPChannel PSM: CBL2CAPPSM,error: Error?) {
print(PSM)
}
func peripheralManager(_ peripheral: CBPeripheralManager,central: CBCentral,didSubscribeto characteristic: CBCharacteristic) {
print("subscirbed!!11")
}
func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager,error: Error?)
{
if let error = error
{
print("Failed due to error: \(error)")
return
}
print("Advertisement Success!")
}
func peripheralManager(_ peripheral: CBPeripheralManager,didReceiveRead request: CBATTRequest)
{
print("Received read request!")
peripheralManager.respond(to: request,withResult: CBATTError.success)
print(request)
}
func peripheralManager(_ peripheral: CBPeripheralManager,didReceiveWrite requests: [CBATTRequest]) {
print("huiewf")
}
func peripheralManager(_ peripheral: CBPeripheralManager,didAdd service: CBService,error: Error?) {
print("Added \(service.className)")
}
}
let myPeripheral = Peripheral()
我看了看HOGP文档,对于可能的问题我有一些想法,但是我不知道如何实现它们。我可能没有正确设置这些标志,但是我在网上看了一下,不确定如何更改它。我的L2CAP频道可能使用了错误的PSM,但是我不知道在发布L2CAP频道时如何指定要打开哪个PSM。 didReceiveRead
请求未运行,没有错误消息,并且didOpen channel
未运行。我相信已经添加了HOGP的所有依赖项(HID,设备信息,电池)。我在做什么错了?
更新:外围设备在连接15秒后,中央服务器尝试发现服务,然后断开连接。我注意到的另一件事是,当我尝试发现服务时,信号之间的间隔(nRF Connect上的符号)更改为N / A,但我不知道这是否相关。 iPad HCI(文本):
Mac HCI(文本)
Aug 22 21:53:48.536 HCI Command 0x0000 Read Local Name
Aug 22 21:53:48.541 HCI Event 0x0000 Command Complete [0C14] - Read Local Name - Local Name: Virtus’s Mac
Aug 22 21:53:48.564 HCI Command 0x0000 LE Set Advertise Enable - 0x00
Aug 22 21:53:48.567 HCI Event 0x0000 Command Complete [200A] - LE Set Advertise Enable
Aug 22 21:53:48.567 HCI Command 0x0000 LE Set Scan Response Data
Aug 22 21:53:48.569 HCI Event 0x0000 Command Complete [2009] - LE Set Scan Response Data
Aug 22 21:53:48.569 HCI Command 0x0000 LE Set Advertising Data
Aug 22 21:53:48.571 HCI Event 0x0000 Command Complete [2008] - LE Set Advertising Data
Aug 22 21:53:48.571 HCI Command 0x0000 LE Set Advertising Parameters - Min/Max Interval:181.25ms/181.25ms
Aug 22 21:53:48.573 HCI Event 0x0000 Command Complete [2006] - LE Set Advertising Parameters
Aug 22 21:53:48.573 HCI Command 0x0000 LE Set Advertise Enable - 0x01
Aug 22 21:53:48.576 HCI Event 0x0000 Command Complete [200A] - LE Set Advertise Enable
Aug 22 21:53:49.439 HCI Event 0x0000 7D:40:87:A2:15:5D LE - Advertising Report - 1 Report - normal - Random - 7D:40:87:A2:15:5D -78 dBm - Channel 37
Aug 22 21:53:50.335 HCI Event 0x0000 F9:28:A5:E6:F3:FC LE - Advertising Report - 1 Report - normal - Random - F9:28:A5:E6:F3:FC -59 dBm - Channel 37
Aug 22 21:53:50.951 HCI Event 0x0000 48:61:60:D8:45:E0 LE - Advertising Report - 1 Report - normal - Random - 48:61:60:D8:45:E0 -69 dBm - Channel 37
Aug 22 21:53:51.752 HCI Event 0x0E01 7A:C5:9B:D1:89:F5 LE - Connection Complete - Slave - Random - 7A:C5:9B:D1:89:F5 - Conn Interval: 30 ms
Aug 22 21:53:51.756 Kernel 0x0000 Success setIdlePolicy (0 ms) Interrupt Pipe
Aug 22 21:53:51.756 Kernel 0x0000 Success setIdlePolicy (0 ms) Bulk Pipe
Aug 22 21:53:51.759 HCI Command 0x0E01 7A:C5:9B:D1:89:F5 Read RSSI - Connection Handle: 0x0E01
Aug 22 21:53:51.761 HCI Event 0x0000 Command Complete [1405] - Read RSSI - RSSI: Unavailable
Aug 22 21:53:51.762 HCI Command 0x0000 Read Scan Enable
Aug 22 21:53:51.763 HCI Event 0x0000 Command Complete [0C19] - Read Scan Enable - Scan State: 0x00 - Scan Enable: 0x00
Aug 22 21:53:51.763 HCI Command 0x0E01 7A:C5:9B:D1:89:F5 Read RSSI - Connection Handle: 0x0E01
Aug 22 21:53:51.765 HCI Event 0x0000 Command Complete [1405] - Read RSSI - RSSI: Unavailable
Aug 22 21:53:51.767 HCI Command 0x0E01 7A:C5:9B:D1:89:F5 Read RSSI - Connection Handle: 0x0E01
Aug 22 21:53:51.769 HCI Event 0x0000 Command Complete [1405] - Read RSSI - RSSI: Unavailable
Aug 22 21:53:51.771 HCI Command 0x0E01 7A:C5:9B:D1:89:F5 Read RSSI - Connection Handle: 0x0E01
Aug 22 21:53:51.773 HCI Event 0x0000 Command Complete [1405] - Read RSSI - RSSI: Unavailable
Aug 22 21:53:51.774 HCI Command 0x0000 LE Create Connection Cancel
Aug 22 21:53:51.776 HCI Event 0x0000 Command Complete [200E] - LE Create Connection Cancel - Command disallowed
Aug 22 21:53:51.776 Kernel 0x0000 Received Command disallowed (0x0C) error -- In UHE mode?
Aug 22 21:53:51.776 Kernel 0x0000 Not in UHE Mode -- continue
Aug 22 21:53:51.777 ATT Send 0x0E01 7A:C5:9B:D1:89:F5 Read By Group Type Request - Start Handle: 0x0001 - End Handle: 0xFFFF - UUID: GATT Primary Service Declaration
Aug 22 21:53:51.929 ATT Receive 0x0E01 7A:C5:9B:D1:89:F5 Exchange MTU Request - MTU: 185
Aug 22 21:53:51.932 ATT Send 0x0E01 7A:C5:9B:D1:89:F5 Exchange MTU Response - MTU: 104
Aug 22 21:53:52.154 HCI Event 0x0000 FC:BE:EE:F7:4F:22 LE - Advertising Report - 1 Report - normal - Random - FC:BE:EE:F7:4F:22 -67 dBm - Channel 37
Aug 22 21:53:52.754 HCI Event 0x0000 7E:7A:E5:92:8D:DA LE - Advertising Report - 1 Report - normal - Random - 7E:7A:E5:92:8D:DA -76 dBm - Channel 37
Aug 22 21:53:56.062 HCI Command 0x0000 LE Set Scan Enable - 0x00,Filter Duplicates: 1
Aug 22 21:53:56.330 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable
Aug 22 21:53:56.331 HCI Command 0x0000 LE Set Scan Enable - 0x00,Filter Duplicates: 1
Aug 22 21:53:56.332 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable - Command disallowed
Aug 22 21:53:56.332 Kernel 0x0000 Received Command disallowed (0x0C) error -- In UHE mode?
Aug 22 21:53:56.332 Kernel 0x0000 Not in UHE Mode -- continue
Aug 22 21:53:56.333 HCI Command 0x0000 LE Create Connection Cancel
Aug 22 21:53:56.334 HCI Event 0x0000 Command Complete [200E] - LE Create Connection Cancel - Command disallowed
Aug 22 21:53:56.334 Kernel 0x0000 Received Command disallowed (0x0C) error -- In UHE mode?
Aug 22 21:53:56.334 Kernel 0x0000 Not in UHE Mode -- continue
Aug 22 21:53:56.334 HCI Command 0x0000 LE Set Scan Parameters - Passive - 30/300 (ms)
Aug 22 21:53:56.336 HCI Event 0x0000 Command Complete [200B] - LE Set Scan Parameters
Aug 22 21:53:56.336 HCI Command 0x0000 LE Set Scan Enable - 0x01,Filter Duplicates: 1
Aug 22 21:53:56.339 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable
Aug 22 21:53:56.339 HCI Command 0x0000 LE Set Scan Enable - 0x00,Filter Duplicates: 1
Aug 22 21:53:56.342 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable
Aug 22 21:53:56.343 HCI Command 0x0000 LE Set Scan Enable - 0x00,Filter Duplicates: 1
Aug 22 21:53:56.344 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable - Command disallowed
Aug 22 21:53:56.344 Kernel 0x0000 Received Command disallowed (0x0C) error -- In UHE mode?
Aug 22 21:53:56.344 Kernel 0x0000 Not in UHE Mode -- continue
Aug 22 21:53:56.344 HCI Command 0x0000 LE Create Connection Cancel
Aug 22 21:53:56.346 HCI Event 0x0000 Command Complete [200E] - LE Create Connection Cancel - Command disallowed
Aug 22 21:53:56.346 Kernel 0x0000 Received Command disallowed (0x0C) error -- In UHE mode?
Aug 22 21:53:56.346 Kernel 0x0000 Not in UHE Mode -- continue
Aug 22 21:53:56.346 HCI Command 0x0000 LE Set Scan Parameters - Passive - 30/300 (ms)
Aug 22 21:53:56.348 HCI Event 0x0000 Command Complete [200B] - LE Set Scan Parameters
Aug 22 21:53:56.349 HCI Command 0x0000 LE Set Scan Enable - 0x01,Filter Duplicates: 1
Aug 22 21:53:56.350 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable
Aug 22 21:53:56.356 HCI Event 0x0000 68:27:37:44:5E:BB LE - Advertising Report - 1 Report - normal - Public - 68:27:37:44:5E:BB -67 dBm - Manufacturer Specific Data - Channel 37
Aug 22 21:53:56.382 HCI Event 0x0000 7A:C5:9B:D1:89:F5 LE - Advertising Report - 1 Report - normal - Random - 7A:C5:9B:D1:89:F5 -36 dBm - Channel 37
Aug 22 21:53:56.406 HCI Event 0x0000 A4:30:7A:57:FA:09 LE - Advertising Report - 1 Report - normal - Public - A4:30:7A:57:FA:09 -63 dBm - Manufacturer Specific Data - Channel 37
Aug 22 21:53:56.720 HCI Event 0x0000 48:61:60:D8:45:E0 LE - Advertising Report - 1 Report - normal - Random - 48:61:60:D8:45:E0 -69 dBm - Channel 37
Aug 22 21:53:56.730 HCI Event 0x0000 22:BA:93:E1:96:97 LE - Advertising Report - 1 Report - normal - Random - 22:BA:93:E1:96:97 -80 dBm - Channel 37
Aug 22 21:53:58.157 HCI Event 0x0000 FC:BE:EE:F7:4F:22 LE - Advertising Report - 1 Report - normal - Random - FC:BE:EE:F7:4F:22 -64 dBm - Channel 37
Aug 22 21:53:58.178 HCI Event 0x0000 40:8F:F9:84:72:47 LE - Advertising Report - 1 Report - normal - Random - 40:8F:F9:84:72:47 -85 dBm - Channel 37
Aug 22 21:53:58.757 HCI Event 0x0000 F4:4B:91:7C:3E:1F LE - Advertising Report - 1 Report - normal - Random - F4:4B:91:7C:3E:1F -67 dBm - Channel 37
Aug 22 21:53:59.102 HCI Event 0x0000 7E:7A:E5:92:8D:DA LE - Advertising Report - 1 Report - normal - Random - 7E:7A:E5:92:8D:DA -80 dBm - Channel 37
Aug 22 21:53:59.685 HCI Event 0x0000 56:50:B9:E4:64:59 LE - Advertising Report - 1 Report - normal - Random - 56:50:B9:E4:64:59 -77 dBm - Channel 37
Aug 22 21:54:00.876 HCI Event 0x0000 DA:2D:93:7D:BB:E9 LE - Advertising Report - 1 Report - normal - Random - DA:2D:93:7D:BB:E9 -60 dBm - Channel 37
Aug 22 21:54:01.214 HCI Event 0x0000 90:DD:5D:95:81:A4 LE - Advertising Report - 1 Report - normal - Public - 90:DD:5D:95:81:A4 -79 dBm - Channel 37
Aug 22 21:54:01.475 HCI Event 0x0000 F9:28:A5:E6:F3:FC LE - Advertising Report - 1 Report - normal - Random - F9:28:A5:E6:F3:FC -61 dBm - Channel 37
Aug 22 21:54:02.053 HCI Event 0x0000 19:B4:23:FD:F3:D5 LE - Advertising Report - 1 Report - normal - Random - 19:B4:23:FD:F3:D5 -80 dBm - Channel 37
Aug 22 21:54:05.652 HCI Event 0x0000 58:4E:6C:22:C8:E6 LE - Advertising Report - 1 Report - normal - Random - 58:4E:6C:22:C8:E6 -73 dBm - Channel 37
Aug 22 21:54:06.160 HCI Command 0x0000 LE Set Scan Enable - 0x00,Filter Duplicates: 1
Aug 22 21:54:06.164 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable
Aug 22 21:54:06.165 HCI Command 0x0000 LE Set Scan Enable - 0x00,Filter Duplicates: 1
Aug 22 21:54:06.169 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable - Command disallowed
Aug 22 21:54:06.169 Kernel 0x0000 Received Command disallowed (0x0C) error -- In UHE mode?
Aug 22 21:54:06.169 Kernel 0x0000 Not in UHE Mode -- continue
Aug 22 21:54:06.169 HCI Command 0x0000 LE Create Connection Cancel
Aug 22 21:54:06.172 HCI Event 0x0000 Command Complete [200E] - LE Create Connection Cancel - Command disallowed
Aug 22 21:54:06.172 Kernel 0x0000 Received Command disallowed (0x0C) error -- In UHE mode?
Aug 22 21:54:06.172 Kernel 0x0000 Not in UHE Mode -- continue
Aug 22 21:54:06.172 HCI Command 0x0000 LE Set Scan Parameters - Passive - 30/300 (ms)
Aug 22 21:54:06.175 HCI Event 0x0000 Command Complete [200B] - LE Set Scan Parameters
Aug 22 21:54:06.175 HCI Command 0x0000 LE Set Scan Enable - 0x01,Filter Duplicates: 1
Aug 22 21:54:06.178 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable
Aug 22 21:54:06.179 HCI Command 0x0000 LE Set Scan Enable - 0x00,Filter Duplicates: 1
Aug 22 21:54:06.208 HCI Event 0x0000 58:4E:6C:22:C8:E6 LE - Advertising Report - 1 Report - normal - Random - 58:4E:6C:22:C8:E6 -71 dBm - Channel 37
Aug 22 21:54:06.209 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable
Aug 22 21:54:06.211 HCI Command 0x0000 LE Set Scan Enable - 0x00,Filter Duplicates: 1
Aug 22 21:54:06.215 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable - Command disallowed
Aug 22 21:54:06.215 Kernel 0x0000 Received Command disallowed (0x0C) error -- In UHE mode?
Aug 22 21:54:06.215 Kernel 0x0000 Not in UHE Mode -- continue
Aug 22 21:54:06.215 HCI Command 0x0000 LE Create Connection Cancel
Aug 22 21:54:06.218 HCI Event 0x0000 Command Complete [200E] - LE Create Connection Cancel - Command disallowed
Aug 22 21:54:06.218 Kernel 0x0000 Received Command disallowed (0x0C) error -- In UHE mode?
Aug 22 21:54:06.218 Kernel 0x0000 Not in UHE Mode -- continue
Aug 22 21:54:06.218 HCI Command 0x0000 LE Set Scan Parameters - Passive - 30/300 (ms)
Aug 22 21:54:06.220 HCI Event 0x0000 Command Complete [200B] - LE Set Scan Parameters
Aug 22 21:54:06.221 HCI Command 0x0000 LE Set Scan Enable - 0x01,Filter Duplicates: 1
Aug 22 21:54:06.223 HCI Event 0x0000 Command Complete [200C] - LE Set Scan Enable
Aug 22 21:54:06.547 HCI Event 0x0000 90:DD:5D:95:81:A4 LE - Advertising Report - 1 Report - normal - Public - 90:DD:5D:95:81:A4 -79 dBm - Channel 37
Aug 22 21:54:06.577 HCI Event 0x0000 58:4E:6C:22:C8:E6 LE - Advertising Report - 1 Report - normal - Random - 58:4E:6C:22:C8:E6 -73 dBm - Channel 37
Aug 22 21:54:06.778 HCI Command 0x0E01 7A:C5:9B:D1:89:F5 disconnect - Connection Handle: 0x0E01 - Reason: Remote User Terminated Connection
Aug 22 21:54:06.778 Kernel 0x0000 Success setIdlePolicy (0 ms) Interrupt Pipe
Aug 22 21:54:06.778 Kernel 0x0000 Success setIdlePolicy (0 ms) Bulk Pipe
Aug 22 21:54:06.779 Kernel 0x0000 Success setIdlePolicy (0 ms) Interrupt Pipe
Aug 22 21:54:06.779 Kernel 0x0000 Success setIdlePolicy (0 ms) Bulk Pipe
Aug 22 21:54:06.800 HCI Event 0x0000 Command Status - disconnect
Aug 22 21:54:06.801 HCI Command 0x0000 LE Set Scan Response Data
Aug 22 21:54:06.803 HCI Event 0x0000 Command Complete [2009] - LE Set Scan Response Data
Aug 22 21:54:06.803 HCI Command 0x0000 Read Scan Enable
Aug 22 21:54:06.805 HCI Event 0x0000 Command Complete [0C19] - Read Scan Enable - Scan State: 0x00 - Scan Enable: 0x00
Aug 22 21:54:06.805 HCI Command 0x0000 LE Set Advertising Data
Aug 22 21:54:06.807 HCI Event 0x0000 Command Complete [2008] - LE Set Advertising Data
Aug 22 21:54:06.807 HCI Command 0x0000 LE Set Advertising Parameters - Min/Max Interval:181.25ms/181.25ms
Aug 22 21:54:06.809 HCI Event 0x0000 Command Complete [2006] - LE Set Advertising Parameters
Aug 22 21:54:06.809 HCI Command 0x0000 LE Set Advertise Enable - 0x01
Aug 22 21:54:06.811 HCI Event 0x0000 Command Complete [200A] - LE Set Advertise Enable
Aug 22 21:54:06.839 HCI Event 0x0E01 7A:C5:9B:D1:89:F5 disconnection Complete - Success
Aug 22 21:54:06.856 Kernel 0x0000 [IOBluetoothDevice][free] -- device with connection handle 0x0e01 is removed
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)