1

I'm working with a Bluetooth Device, in detail I need to:

  • connect
  • discover services
  • discover characteristics
  • get some data
  • disconnect

It is done continuously and works perfectly, except that after few minutes I start receiving strange results, since the peripheral:didDiscoverServices: gives me these logs:

Peripheral state: 2
Error: Error Domain=CBErrorDomain Code=3 "The specified device is not connected." UserInfo={NSLocalizedDescription=The specified device is not connected.}

Code used to get the logs:

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {

    NSLog(@"Peripheral state: %li", (long)peripheral.stat);
    NSLog(@"Error: %@", error);
}

I tried to check for race conditions, but all the callbacks are received on the same queue and only 1 operation is active (next one is started after disconnecting successfully).

Reading the documentation, it is possible to receive an error in case something goes wrong, but how can the Peripheral be in the Connected AND Not Connected state at the same time?

My idea:

  • My device has something wrong.
  • There is an internal limit in the CB component in the way it handle requests
  • Bug in the CB
  • It's perfectly fine, but not well documented (in this case, how to handle it)

Thanks for helping!

Marco Pace
  • 3,820
  • 19
  • 38
  • Are you getting the data from the same peripheral each time? If yes, then why not just stay connnected. Have you implemented the `didDisconnect` and `didFailToConnect` delegate methods? – Paulw11 Dec 20 '17 at 12:28
  • Hi Paulw11, yeah I get data from the same device each time and unfortunately I can't stay connected - request from high level :). Implemented, and the `didDisconnect` get called only after the `peripheral:didDiscoverServices:` is called - but it's called because I disconnect each time. – Marco Pace Dec 20 '17 at 12:52

0 Answers0