Android Ble Connection Time Interval

Android BLE Connection time interval

When I studied the Android BLE API, I could not find an API for changing the connection interval and supervision timeout (maybe slave latency as well, can't remember from the top of my head). I you do need to change these, you must do it from the slave device.

The answer from Ashwini you can just ignore, what he says is simply not correct. A Bluetooth 4.0 compliant master device must support connection intervals from 7.5 ms up to 4.0s. The slave device may request a change in connection parameters and sends a connection parameter update request, and the master will update the connection parameter accordingly.

On the other hand, the master (in your case the Android device) could have an interest in changing the connection interval on its own, in order to save power, and you would like to change the connection interval to a more relaxed interval.

In my opinion the Android API and even the hardware implementation on several devices are immature and using BLE, in the sense that BLE was intended, draws to much power on an Android device. In the future I believe you will see much better support on the API level and a division of the host and controller so that the controller can maintain connectivity even when the main CPU of the mobile device is sleeping. That will save a lot of power and you can maintain connectivity with your BLE devices 24/7 without any major constrain on you battery life.

Benchmarking connection time interval in Android across different phones

I manage to solve this issue by timing the following callback on my Android app:

@Override public void onCharacteristicChanged(BluetoothGatt gatt,BluetoothGattCharacteristic 
{
/* Timing code measuring msecs between calls. */
}

This has worked perfectly to perform the benchmark I was looking for.

Android BLE onConnectionUpdated()

Below is the source code for onConnectionUpdated


            /**
* Callback invoked when the given connection is updated
* @hide
*/
@Override
public void onConnectionUpdated(String address, int interval, int latency,
int timeout, int status) {
if (DBG) {
Log.d(TAG, "onConnectionUpdated() - Device=" + address
+ " interval=" + interval + " latency=" + latency
+ " timeout=" + timeout + " status=" + status);
}
if (!address.equals(mDevice.getAddress())) {
return;
}
runOrQueueCallback(new Runnable() {
@Override
public void run() {
final BluetoothGattCallback callback = mCallback;
if (callback != null) {
callback.onConnectionUpdated(BluetoothGatt.this, interval, latency,
timeout, status);
}
}
});
}

You can file the complete source code in BluetoothGatt.java


Additionally on source code on the server is

 /**
* Callback indicating the connection parameters were updated.
*
* @param device The remote device involved
* @param interval Connection interval used on this connection, 1.25ms unit. Valid range is from
* 6 (7.5ms) to 3200 (4000ms).
* @param latency Slave latency for the connection in number of connection events. Valid range
* is from 0 to 499
* @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is from 10
* (0.1s) to 3200 (32s)
* @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated
* successfully
* @hide
*/
public void onConnectionUpdated(BluetoothDevice device, int interval, int latency, int timeout,
int status) {
}

This can be found at BluetoothGattServerCallback.java



Related Topics



Leave a reply



Submit