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!