BleService

interface BleService(source)

Represents a BLE service for commonMain.

Inheritors

Functions

Link copied to clipboard

Creates a handle for a characteristic belonging to this service.

Link copied to clipboard
abstract fun hasCharacteristic(characteristic: BleCharacteristic): Boolean

Returns true when the characteristic is present on the connected device.

Link copied to clipboard
abstract fun observe(characteristic: BleCharacteristic): Flow<ByteArray>

Observes notifications/indications from the characteristic.

open fun observe(characteristic: BleCharacteristic, onSubscription: suspend () -> Unit): Flow<ByteArray>

Observes notifications/indications from the characteristic with an onSubscription action that fires after notifications are enabled (CCCD written).

Link copied to clipboard
abstract fun preferredWriteType(characteristic: BleCharacteristic): BleWriteType

Returns the preferred write type for the characteristic on this platform/device.

Link copied to clipboard
abstract suspend fun read(characteristic: BleCharacteristic): ByteArray

Reads the characteristic value once.

Link copied to clipboard
abstract suspend fun write(characteristic: BleCharacteristic, data: ByteArray, writeType: BleWriteType)

Writes a value to the characteristic using the requested BLE write type.