Hi guys, I am making an android app to control a L...
# juul-libraries
Hi guys, I am making an android app to control a LED from my phone through BLE. This is my first time using Kable and I would appreciate having your opinion on the way I am using it. I have prepared a small gist where you can see my implementation: https://gist.github.com/glsubri/ac280b594d0c68b3dc1b3bcfdc7b7b7b. I also had a small question: is it normal that it takes something like a minute to connect to my Bluetooth device ? Am I missing something with kable or is it my micro-controller ? Thanks!
Overall, seems like reasonable/good usage of Kable. I do have some small pointers that might improve a few things: Kable doesn't care what Dispatcher you use for all its functions (internally it uses either a dedicated thread or a
, depending on the Android version, to manage threading for I/O operations), so your use of
to interact with Kable doesn't hurt anything, but also isn't necessary (and may be resulting in unnecessary context switches). The same is also true for your usages of
, you don't need
for those. I'd recommend you make
suspend and then you can remove the
within that function. We plan to later either introduce another
or make
emit after service discovery, so it will likely remove your need to manage your own
state. https://github.com/JuulLabs/kable/issues/75 By having
suspend also means that failures in that function will propagate through Kable's
method, which IMHO will make your error handling simpler. Since your
method is `launch`ing, it may cause issues in your
function. Since you should "wait" for disconnect to complete before attempting another connection. So it would be better if your
called either suspend version of your
function or just used
directly. Re: it taking a minute to connect; that does seem like a really long time, I haven't see something like that. I'm used to connections taking less than 10 seconds (assuming peripheral is near the Android phone). We'll be adding logging to Kable soon, which might help diagnose issues related to your connections taking a long time. 🤞 https://github.com/JuulLabs/kable/issues/130
@travis Thanks for the insights, I will probably switch to
functions. Also, thanks for the library, it's really nice 👍
👍 1
Also, thanks for the library, it's really nice 👍
Thanks for the kind words, glad it is working well for you. 😄