Is this actually a response to my other posting from today, about multiple didConnectPeripheral callbacks?
I actually run the connection process through a state machine, because the process of connection includes the initial connect request to CB, enumeration of services, enumerations of characteristics per service, setting the notification property on one of the characteristics, and finally conducting a security operation with the peripheral.
However, the multiple didConnectPeripheral callbacks seems to be a recent phenomenon, and what I’m wondering about is a) is CB really establishing two connection sessions to the same peripheral; and b) when I receive the second callback and realize it’s extraneous to my app, do I have to call cancelPeripheralConnection on one of the CBPeripheral objects to clean up that connection?; c) if I have a CBPeripheral objects that represents a connection to a specific hardware device, and at the same time I have another CBPeripheral objects that represents a connection to that same specific hardware device, are those CBPeripheral objects identical?
/Don
We used this bluetooth low energy packet sniffer from TI:
I was able to confirm that there was actually no BLE traffic at the time, leading me to believe that the initial "didConnectPeripheral" is false and does not correspond to BLE traffic on the radio.
For my application, we keep track of what state we are in. So, I added some code that looks like:
public func centralManager(central: CBCentralManager!, didDisconnectPeripheral peripheral: CBPeripheral!, error: NSError!) {
// Sometimes the other end drops the connection while we are in .Connected (but not yet .ConnectedPiped)
// we can do this over and over since there is a connect timeout watching.
if(.Connected == state) {
self.central.connectPeripheral(peripheral, options: nil)
The states of 'state' are:
.Disconnected = we have not connected yet.
.Connected = we made it to didConnectPeripheral and stored a reference to peripheral
.ConnectedPiped = remote has subscribed to our characteristic
In most cases it only takes one retry to reconnect and now everything works smoothly.
Good luck,
Justin