One saves only the minimal amount of data about the device (the services, its paired state and keys, etc.). Instead what one does is continuously scan and connect to a desired device by inspecting its advertisement. The other downside is that for each device you want to auto-reconnect to you have to keep a BluetoothGatt object performing a pending connection. Update: While the above approach works in general, it is sometimes agonizingly slow probably because the pending connection uses extremely conservative scan rates. Then when the device disconnects, invoke a nnect(). You have to trap the paired event in a BroadcastReceiver and do a nnectGatt() setting the autoconnect to true. Well after many trials and tribulations this is how I best get the Android to auto connect with the only user action being to first select the device (if using the settings menu then first pairing). Maybe the auto-connect was NOT meant to re-connect as I indicated above? Does anyone know how to do this? Does anyone really know how autoconnect and gatt.close() are to work? I do not want to start my own scan but somehow set the background scanning rate used by Android for the reconnect. So what I think I need to do is to somehow set the background scan rate used by the Android to a higher duty cycle (only possible in 5.0 and up) when auto-connect has been set but I do not know how to do this. I am not sure because there is no way to detect the scanning operation like there is advertisements! It is also possible the scanning stops after a certain amount of time but there is no documentation on that. It is, however, unreliable and it may be unreliable due to a very low-duty scan cycle and the device quitting advertising before a scan cycle actually detects the advertisement. Sometimes it can take a long time, especially after version 5.0. If I have not called gatt.close() and have not power cycled the Android, the auto-connection usually happens. But if I do call gatt.close() the Android central app never reconnects. Everywhere I look I see that one should call gatt.close(). When the device disconnects, do not call gatt.close(). The first step is to connect or pair and connect to a new device setting the 'autoconnect' parameter to 'true'. What I have done seems to work but it works poorly. One of the ideas of BTLE devices is that one saves service, bonding, and enabling states such that a reconnect is VERY fast and consumes very little power on the peripheral. My goal is to get the Android device to reconnect to a BLE device that it has previously connected to without user intervention in the same way it does for a classic BT paired device does (even works through power cycles).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |