Peripheral

interface Peripheral : CoroutineScope

Inheritors

Properties

Link copied to clipboard
Link copied to clipboard
abstract val identifier: Identifier

Platform specific identifier for the remote peripheral. On some platforms, this can be used to "restore" a previously known peripheral for reconnection.

Link copied to clipboard
abstract val name: String?

The peripheral name, as provided by the underlying bluetooth system. This value is system dependent and is not necessarily the Generic Access Profile (GAP) device name.

Link copied to clipboard
abstract val services: StateFlow<List<DiscoveredService>?>

The list of services (GATT profile) which have been discovered on the remote peripheral.

Link copied to clipboard
abstract val state: StateFlow<State>

Provides a conflated Flow of the Peripheral's State.

Functions

Link copied to clipboard
abstract suspend fun connect(): CoroutineScope

Initiates a connection, suspending until connected, or failure occurs. Multiple concurrent invocations will all suspend until connected (or failure occurs). If already connected, then returns immediately.

Link copied to clipboard
abstract suspend fun disconnect()

Disconnects the active connection, or cancels an in-flight connection attempt, suspending until Peripheral has settled on a disconnected state.

Link copied to clipboard
abstract fun observe(characteristic: Characteristic, onSubscription: OnSubscriptionAction = {}): Flow<ByteArray>

Observes changes to the specified Characteristic.

Link copied to clipboard
fun CoroutineScope.peripheral(bluetoothDevice: BluetoothDevice, builderAction: PeripheralBuilderAction = {}): Peripheral
fun CoroutineScope.peripheral(identifier: Identifier, builderAction: PeripheralBuilderAction = {}): Peripheral
expect fun CoroutineScope.peripheral(advertisement: Advertisement, builderAction: PeripheralBuilderAction = {}): Peripheral
actual fun CoroutineScope.peripheral(advertisement: Advertisement, builderAction: PeripheralBuilderAction): Peripheral
actual fun CoroutineScope.peripheral(advertisement: Advertisement, builderAction: PeripheralBuilderAction): Peripheral
Link copied to clipboard
abstract suspend fun read(characteristic: Characteristic): ByteArray

Reads data from characteristic.

abstract suspend fun read(descriptor: Descriptor): ByteArray

Reads data from descriptor.

Link copied to clipboard
abstract suspend fun rssi(): Int

On JavaScript, requires Chrome 79+ with the chrome://flags/#enable-experimental-web-platform-features flag enabled.

Link copied to clipboard
abstract suspend fun write(descriptor: Descriptor, data: ByteArray)

Writes data to descriptor.

abstract suspend fun write(characteristic: Characteristic, data: ByteArray, writeType: WriteType = WithoutResponse)

Writes data to characteristic.