/trikot.bluetooth

Primary LanguageKotlinBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

⚠️ Warning: this project as been moved

See the new trikot repository for releases starting from 3.0.0.

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
    maven { url('https://s3.amazonaws.com/mirego-maven/public') }

    api "com.mirego.trikot:bluetooth:$trikot_bluetooth_version"
    jvm "com.mirego.trikot:bluetooth-jvm:$trikot_bluetooth_version"
    js "com.mirego.trikot:bluetooth-js:$trikot_bluetooth_version"
    iosx64 "com.mirego.trikot:bluetooth-iosx64:$trikot_bluetooth_version"
    iosarm64 "com.mirego.trikot:bluetooth-iosarm64:$trikot_bluetooth_version"

License

Trikot.bluetooth is © 2018-2019 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md file.

About Mirego

Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We’re a team of talented people who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.

We also love open-source software and we try to give back to the community as much as we can.