Elegant implementation of Multiplatform Bluetooth in ReactiveStreams.
Discover devices
BluetoothConfiguration.bluetoothManager.scanForDevice(cancellableManager, listOf("UUIDS")).subscribe(cancellableManager) {
// List of BluetoothScanResult
}Connect to device
val bluetoothScanResult = ...
val device = bluetoothScanResult.connect(cancellableManager)
device.isConnected.subscribe(cancellableManager) {
// True when connected
}Retrieve AttributeProfileServices
val services = device.attributeProfileServices.subscribe(cancellableManager) {
// Map of UUIDs - AttributeProfileService
}Retrieve AttributeProfileCharacteristics
val attributeProfileService = ... attributeProfileService.characteristics.subscribe(cancellableManager) {
// Map of UUIDs - AttributeProfileCharacteristic
}Receive event (value or error)
val attributeProfileCharacteristic = ... attributeProfileCharacteristic.event.subscribe(cancellableManager) {
// AttributeProfileCharacteristicEvent
}Read value
attributeProfileCharacteristic.read()Write value
val byteArray = ...
attributeProfileCharacteristic.write(byteArray)Watch value (subscribe for value change). Must call the right method depending on the characteristic type.
attributeProfileCharacteristic.watch()
// OR
attributeProfileCharacteristic.watchWithIndication()See swift extensions for more information.
val context = this // application context
BluetoothConfiguration.bluetoothManager = AndroidBluetoothManager(context) dependencies {
maven { url("https://s3.amazonaws.com/mirego-maven/public") }
}
ios() {
binaries {
framework {
export "com.mirego.trikot:bluetooth:$trikot_version"
}
}
}
sourceSets {
commonMain {
dependencies {
implementation "com.mirego.trikot:bluetooth:$trikot_version"
}
}
}