Random peripheral disconnects when WiFi is enabled

The app I'm working on connects iPhone/iPad to a BLE peripheral device, with received notification every 5 seconds.

All works well most of the time,

On occasion, after many days of faultless operation, I'll start seeing unanounced disconnects - didDisconnectPeripheral, with

didDisconnectPeripheral Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly."


Once these disconnects start, they continue randomly, at no particular time interval or place within my code.

Initially the only way I found to stop the disconnects was to power off / on the iPhone, but the problem would eventually return

I have recently found that if I disable WiFi the problem goes away, re-enabling wifi disconnections return


I have also found the issue looks to be occuring with other apps, Punch Through Design's Light Blue gives "Disconnection Alerts" whenever I have WiFi turned on.


iOS version I'm working with is 8.1, but has been reported on 8.3.


Any suggestions for a solution would be most appreciated

Replies

Seeing similar activity after a long period of sleep by an iPad talking to a BLE peripheral. Only thing that I've found to fix it is power cycle the iPad. Definitely happens in 8.1, trying to reproduce it in 8.3 but it happens pretty rarely for me.


Let's keep each other posted on this.

The cause for random disconnects usually comes from the peripheral side rather than the app side.

Some peripheral manufacturers, either in order to save battery, or perhaps to decrease response time, use connection parameters that are unsuited for the use case and the hardware configuration of the peripherals.


First, it is important to consult section 3.6 of the Bluetooth Accessory Design Guidelines for Apple Products: https://developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf


This document lists a recommended set of connection parameters which are related to each other. The peripheral is responsible for requesting these parameters correctly. There are several parameters which are related to each other, so they must be considered as a whole.

1. Interval Max * (***** Latency + 1) ≤ 2 seconds

2. Interval Min ≥ 20 ms

3. Interval Min + 20 ms ≤ Interval Max

4. ***** Latency ≤ 4

5. connSupervisionTimeout ≤ 6 seconds

6. Interval Max * (***** Latency + 1) * 3 < connSupervisionTimeout


If the parameters are beyond acceptable limits, they will be rejected, but just because they are accepted does not guarantee a spotless operation for all use cases. For example, a peripheral that connects for a few seconds, then disconnects need not worry about long term connection stability, but a peripheral that expects to stay connected for several days does. The manufacturer will need to find the suitable set for their exact use case.


A lot of factors effect the stability of a low energy radio connection, especially RF noise. WiFi also operates on 2.4 MHz and is possible that it effects a borderline connection. Best is to start with a middle of the road set of parameters and then find the set that works for you.


Specifically, the error you are seeing indicates that iOS did not receive a response from the peripheral. The peripheral must be prepared to send a response back within the minimum possible effective connection interval as calculated by the above formulae.