beepiz / blescancoroutines Goto Github PK
View Code? Open in Web Editor NEWEasier and safer Bluetooth Low Energy scanning with Kotlin coroutines.
License: Apache License 2.0
Easier and safer Bluetooth Low Energy scanning with Kotlin coroutines.
License: Apache License 2.0
Since API 24 (Android 7.0), only 5 scan starts are allowed for the app in windows of 30 seconds.
This gotcha is among the not well documented parts of Android BLE.
This should be easy to achieve with Flow
(relates to #5).
Different scan throttling strategies might be allowed.
This will need an instrumented test and/or a test app so we can rest assured all the strategies work as expected with the full range of their allowed parameters.
The reference test advertising device, its software and its config are yet to be determined.
A Raspeberry Pi 3 B running Android Things might be a good choice because of the low price point, and the Android APIs usable from Kotlin.
Last note: It might be interesting to see if we can handle a continuous scan by restarting frequently the scan as it should be easier with Flow
(maybe using old BLE API if it works better), for devices that have malfunctioning bluetooth low energy (can often be determined with ease with Wi-Fi enabled).
Hi,
could you please update your project dependencies. Meanwhile coroutines are stable and not experimental anymore.
The scanner.scan() method returns kotlinx.coroutines.experimental.channels.ReceiveChannel
but I can only import kotlinx.coroutines.channels.ReceiveChannel
Thanks in advance!
In the mobile sample when a user taps on the start scan button the app crashes with the following stack track because the action is not called on the Main Thread.
19232-19252/com.beepiz.blescancoroutines.sample E/MainActivity: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7760) at android.view.ViewRootImpl.focusableViewAvailable(ViewRootImpl.java:3780) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:917) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:917) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:917) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:917) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:917) at android.view.ViewGroup.focusableViewAvailable(ViewGroup.java:917) at android.view.View.setFlags(View.java:14096) at android.view.View.setEnabled(View.java:10016) at android.widget.TextView.setEnabled(TextView.java:2096) at com.beepiz.blescancoroutines.sample.common.extensions.SuspendViewsKt.awaitOneClick(SuspendViews.kt:15) at com.beepiz.blescancoroutines.sample.common.extensions.SuspendViewsKt.awaitOneClick$default(SuspendViews.kt:13) at com.beepiz.blescancoroutines.sample.MainActivity.consumeScanStartStops(MainActivity.kt:74) at com.beepiz.blescancoroutines.sample.MainActivity$consumeScanStartStops$1.invokeSuspend(Unknown Source:12) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32) at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594) at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)
Hi Louis,
The scanChannel
extension function currently returns a Channel
. Do you think a Flow
might be more suitable here?
I'm new to channels/flows/coroutines, so my understanding may not be correct. A Flow
would allow more flexibility in when scanning should actually start - e.g. only after the user calls collect
.
Current API works fine for my needs, but I was curious about your thoughts.
Thanks.
The new invokeOnClose
method added in the version 0.24.0 of kotlinx.coroutines is all we need to stop scan.
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'beepiz_bintray_user' for object of type com.jfrog.bintray.gradle.BintrayExtension.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.