Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreBluetooth repeatedly disconnecting

I've looked up and down for this problem, but no one seems to have it.

I have two iPads. One is acting as a Bluetooth peripheral that is always in the foreground. Since I am more interested in the central side, I have made my central iPad background-capable for BLE-central. My workflow is as follows:

  1. Central app runs and starts scanning
  2. Peripheral advertises service (or comes within range)
  3. Central device connects to peripheral and stops scanning
  4. Peripheral stops advertisement (or leaves range)
  5. Central device disconnects and starts scanning
  6. Do steps 1-5 seamlessly whether the central is in the foreground or background

When I run my central iPad app, steps 3 and 5 repeat every 10 seconds, even though the service is being advertised the entire time. This happens in the foreground and background.

On disconnect, I get this error:

Error occurred while disconnecting peripheral: The specified device has disconnected from us.

Any ideas on why it keeps disconnecting? Does CoreBluetooth clean up the connections if no data is being transferred? Right now, my central is doing a one-off read of peripheral characteristics. It is not subscribing to updates, since the values are static. Thanks!!

like image 436
Big-O Claire Avatar asked Oct 17 '13 16:10

Big-O Claire


1 Answers

In my case the solution was to subscribe to the characteristic regardless of whether the value is static or not. It seems as though subscribing will keep the connection alive, whereas if you read one-off values the framework will try to conserve battery life and drop the connection, forcing you to manually reconnect before performing another read or write.

like image 152
afrederick Avatar answered Oct 21 '22 13:10

afrederick