Skip to content

Latest commit

History

History

trikot-bluetooth

Folders and files

NameName
Last commit message
Last commit date

parent directory

..

Trikot.bluetooth

Elegant implementation of Multiplatform Bluetooth in ReactiveStreams.

Usage

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()

Swift

See swift extensions for more information.

Android

    val context = this // application context
    BluetoothConfiguration.bluetoothManager = AndroidBluetoothManager(context)

Common

Import dependencies
    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"
            }
        }
    }