简体   繁体   English

避免在连接期间从BLE设备发现服务

[英]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. 我正在开发一个具有蓝牙低能耗通信的Android应用程序,我需要与我的BLE设备快速连接。 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. 发现设备的服务需要2秒,这对我的应用程序来说很重要,如果我第一次连接到设备,服务保存在BLE框架的某个缓存中,那么下次我尝试发现服务需要几毫秒时,那就是我的应用程序很好。

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. 问题是,如果我在短时间内与设备断开连接或连接到另一台设备,下次连接到第一台设备时,我需要发现服务并需要2秒钟。

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? 有没有任何方法可以保存服务和特性并将其保存在我的应用程序中,以便下次连接到设备时我不需要发现服务?

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 . 您可以在app保存servicecharacteristic细节。 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. 但是当您尝试读取和写入特征时, BluetoothGatt实例应具有此详细信息,并且只有服务发现会在BluetoothGatt实例中添加服务数据。

So you have to do service discovery in your app at one point of time before using those services/characteristics . 因此,在使用这些services/characteristics之前,您必须在应用程序中的某个时间点进行service discovery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM