-
Notifications
You must be signed in to change notification settings - Fork 11
Is it possible to set the connection priority or the connection interval value? #94
Comments
I'll try to find some time soon to expose that API. Out of curiosity, do you simply want the connection to always have the desired priority, or do you sometimes need to adjust it while connected? Asking to determine the best way to integrate the same functionality in Kable (which will soon supersede Able). |
Thanks 👍 I guess it would suffice to always have the desired priority. |
@virgil85 from what I can tell, there isn't a BluetoothGattCallback function to monitor when the connection priority request has completed, so I presume it must be a fire-and-forget style call? I've add a function that passes through the request, but did not test it. If you could, give it a try and let me know if it works for you. repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
implementation("com.juul.able:core:0.8.1-SNAPSHOT")
} After you're connected you should be able to call: gatt.requestConnectionPriority(Priority.Low) // or Priority.Balanced, or Priority.High Thanks! |
First of all thank you for the quick update. I did test it and it works properly. At least the connection priority part. In my setup I connect to a GPS module which is sending me position updates with 10Hz frequency (via notify). But when I collect the data using the onCharacteristicChanged I often get duplicate data instead of the data that seems to be available when I look at the able logs in verbose mode. This may be due to the preview version of the Kotlin Flow and the error does not occur when I increase the MTU - but perhaps this may be an interesting bug - perhaps really related to the FlowPreview and not the able library but I'm not sure - might be a delay or race condition thing. But thank you again for integrating the connection priority flag. |
What version of Android are you trying this on?
Despite
This is interesting, can you provide a snippet of some of your logs, might help me understand the problem a little better. |
Sorry for the delay. I did test it on Android 9 (Huawei Mate 20X 5G) and on Android 10 (Huawei P20). On Android 9 the error seems to occur a bit more frequent than on Android 10 - but maybe I just had more luck on the Android 10 device 😄 Logs
I switched to Verbose mode before creating the log so the able logs as well as my logs are present. I also attached a simplified version of my onCharacteristicChanged.collect.
I also did not increase the MTU beforehand - so it's the default value. |
Thanks for all the details! Can you change the first line of your val tmpPos = data.value.toString(Charsets.UTF_8) ...and let me know if that resolves your issue, please? |
Wow - that really resolved the problem 😄 Perhaps you just add an example to your documentation detailing the onCharacteristicChanged.collect (and maybe also the other Flow function onConnectionStatusChanged). To avoid that anybody else does the same error as I did. Thank you for solving this issue 😃 |
Thanks for confirming the fix @virgil85. Quick explanation of why it fixed your issue (if you're curious): The problem is that Android re-uses characteristic objects, so accessing data from a characteristic object directly is not thread-safe, as Android may be updating the characteristic data under your feet. Able quickly copies the The fact that Kable, which will be superseding Able soon (#91), only provides the changed data (not the characteristic), so should eliminate accidental misuse of the API. Kable doesn't yet have support for connection priority, but it's on the roadmap (JuulLabs/kable#36). |
Is it possible to tweak connection settings like the interval value?
I saw that normally that is done using
boolean requestConnectionPriority (int connectionPriority)
which I cannot get to work with able.
Even better would be to set the connection time intervals to specific values.
The nRF app does log
Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
when performing such connection parameter changes.
If this is possible, can you provide any code snipped on how to do that?
The text was updated successfully, but these errors were encountered: