Efento Bluetooth library allows scanning for and connecting to Efento Bluetooth Low Energy (BLE) devices.
This Kotlin Multiplatform library is built to support both Android and iOS, and uses kotlin coroutines.
It's intended for use in multiplatform projects targeting Kotlin/Android and Kotlin/Native (iOS).
Add the Efento Maven repository to your project
dependencyResolutionManagement {
repositories {
maven("https://maven.efento.io/releases")
}
}Include the Library Dependency
commonMain.dependencies {
implementation("pl.efento.mobile:bluetooth:2.4.0")
}Initialize the library by passing in the application context.
Android
class Application : Application() {
override fun onCreate() {
super.onCreate()
EfentoBluetooth.init(this)
}
}iOS
EfentoBluetooth.init(IosNoOpApplicationContext()) //application context is not applicable for iOSSet scanner parameters and start collecting device data using the deviceFlow method.
val scanner = EfentoBluetooth.scanner(
//scan parameters
)
scanner.deviceFlow()
.catch { exception ->
//handle exception here
}
.collect { efentoDevice ->
//handle scanned device here
}Define connection parameters and execute commands as needed.
val connection = EfentoBluetooth.sensorConnection(
deviceID = "00010203-0405-0607-0809-0a0b0c0d0e0f",
bluetoothMacAddress = BluetoothMacAddress("28:2C:02:4F:FF:FF"),
resetCode = 1111
//other connection parameters
)
connection.runCatching {
connect()
val measurements = commands.downloadMeasurements() { progress ->
log.debug { "Progress: $progress" }
}
disconnect()
}.onFailure { exception ->
//handle exception here
}Access the full KDoc documentation for detailed information on usage and functions here