Android : auto connect to heartrate sensor ble

259 views Asked by At

I have developed an app that connect to a Polar heart monitor. I connect to it using : device.connectGatt(this, false, mGattCallback); and If I lost the connection I rescan the device and I reconnect to the same hear monitor.

I wonder if I can obtain this behaviours with using :

device.connectGatt(this, true, mGattCallback);

Without re scan the device.

Which is the better way ?

2

There are 2 answers

0
Jerry Ajay On

This isn't possible as of now. The peripheral doesn't take the initiative in establishing a connection once again after it bonds with a device. The central should poll and discover the peripherals presence. This is the architecture of BLE and it's designed in such a way to conserve energy on the peripheral.

Ref: http://www.amazon.com/Inside-Bluetooth-Energy-Artech-Communications/dp/1608075796

Note: This might change if devices start implementing BLE 4.1 and 4.2 standards.

0
user2107373 On

We have observed weird behavior with auto-connect "true". i.e. using connect like below: device.connectGatt(this, true, mGattCallback)

The behavior is unpredictable. At times this does work and automatically connects without having to scan the device again but there were occasions where it did not auto-connect as expected. Also, we observed a strange behavior with auto-connect. The phone connects to device even when the phone Bluetooth is off.

I my opinion scanning for device is the more reliable option.