Connection problems when using iPhone as peripheral

江枫思渺然 提交于 2019-12-06 11:50:49

问题


I am using an iphone as a peripheral to expose some values over bluetooth low energy and using light blue (on another iphone) for debugging. What I am seeing is that the connection with the peripheral is lost after 20 seconds aprox? Any ideas?

Peripheral iPhone: 5c iOS 8.1 Central iPhone with lightblue app: 5s iOS 8.1

Also when I use my Mac Book Pro OS X 10.9.5 with light blue desktop app the connection with the peripheral is lost.

I also tried with another app I wrote to check the connection error and I get the 'the peripheral has disconnected from us' as the error message and this app is working fine with other BLE devices. So the problem is the iPhone when is in peripheral mode.


回答1:


The 20 second delay before diconnection is a classic symptom of security manager issues.

The Security Manager Protocol is a new block added for BLE. The Link Layer will allow a connection, then there is a 20 second gap while the Security Manager has a look to see if it has stored the Long Term Keys that it should have stored after pairing with the device it is now connected to. If it doesn't find those keys, then it will kill the Link Layer connection.

If you don't need a secure connection, then remove the 'EncryptionRequired' attributes when you create your device's attributes:

self.cp_charac = [[CBMutableCharacteristic alloc]
                  initWithType:[CBUUID UUIDWithString:CONTROL_POINT_CHARAC]
                  properties:CBCharacteristicPropertyRead | CBCharacteristicPropertyWrite |
                  CBCharacteristicPropertyWriteWithoutResponse | CBCharacteristicPropertyNotify
                  value:nil
                  permissions:CBAttributePermissionsReadEncryptionRequired | CBAttributePermissionsWriteEncryptionRequired ];

You can see them in the snippet above under permissions.

Page 16 of Security_Manager.pdf from BT SIG website (doc by thomas.t.muller@nmp.nokia.com).

Also look in the BT Spec, https://www.bluetooth.org/en-us/specification/adopted-specifications Page 631 of Core_v4.1.pdf states

If the Security Manager Timer reaches 30 seconds, the procedure shall be con- sidered to have failed, and the local higher layer shall be notified.



来源:https://stackoverflow.com/questions/26920002/connection-problems-when-using-iphone-as-peripheral

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