Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid discover services from BLE device during connection

I'm developing an Android application with Bluetooth low energy communication, and I need a fast connection with my BLE devices. Discovering services of the device takes 2 seconds, that's a lot for my app, if I connect for first time to the device the services are kept in some cache in the BLE framework, then the next time I try to discover services takes miliseconds, that's fine for my app.

The problem is that if I disconnect from the device for a lnog time or I connect to another device, the next time I connect to the first device I need to discover the services and takes 2 seconds.

I only connect to one type of devices and the services and characteristics are known.

I tried to use the bounded(pairing) devices, but when I connect to them there is no services saved and I need to discover it again.

Is there any method to save the services and characteristics and keep it in my app so the next time I connect to a device I don't need to discover services?

like image 365
juan jesus pinuaga Avatar asked May 25 '15 08:05

juan jesus pinuaga


1 Answers

You can connect and no need to discover service at the same time. do service discovery when you need service instances.

Is there any method to save the services and characteristics and keep it in my app so the next time I connect to a device I don't need to discover services?

You can save service and characteristic details in app. but when you try to read and write characteristics then the BluetoothGatt instance should have this detail, and only service discovery adds service data in BluetoothGatt Instance.

So you have to do service discovery in your app at one point of time before using those services/characteristics.

like image 106
AAnkit Avatar answered Sep 23 '22 00:09

AAnkit