GattClientScope


interface GattClientScope


Scope for operations as a GATT client role.

See also
connectGatt

Summary

Public functions

GattService?

Gets the service of the remote device by UUID.

suspend Result<ByteArray>

Reads the characteristic value from the server.

Flow<ByteArray>

Returns a cold Flow that contains the indicated value of the given characteristic.

suspend Result<Unit>

Writes the characteristic value to the server.

Public properties

open List<GattService>

GATT services recently discovered from the remote device.

StateFlow<List<GattService>>

A flow of GATT services discovered from the remote device.

Public functions

getService

Added in 1.0.0-alpha02
fun getService(uuid: UUID): GattService?

Gets the service of the remote device by UUID.

If multiple instances of the same service exist, the first instance of the services is returned.

readCharacteristic

suspend fun readCharacteristic(characteristic: GattCharacteristic): Result<ByteArray>

Reads the characteristic value from the server.

Parameters
characteristic: GattCharacteristic

a remote GattCharacteristic to read

Returns
Result<ByteArray>

the value of the characteristic

subscribeToCharacteristic

Added in 1.0.0-alpha02
fun subscribeToCharacteristic(characteristic: GattCharacteristic): Flow<ByteArray>

Returns a cold Flow that contains the indicated value of the given characteristic.

writeCharacteristic

suspend fun writeCharacteristic(characteristic: GattCharacteristic, value: ByteArray): Result<Unit>

Writes the characteristic value to the server.

Parameters
characteristic: GattCharacteristic

a remote GattCharacteristic to write

value: ByteArray

a value to be written.

Returns
Result<Unit>

the result of the write operation

Throws
kotlin.IllegalArgumentException

if the characteristic doesn't have the write property or the length of the value is greater than the maximum attribute length (512)

Public properties

services

Added in 1.0.0-alpha02
open val servicesList<GattService>

GATT services recently discovered from the remote device.

Note that this can be changed, subscribe to servicesFlow to get notified of services changes.

servicesFlow

Added in 1.0.0-alpha02
val servicesFlowStateFlow<List<GattService>>

A flow of GATT services discovered from the remote device.

If the services of the remote device has changed, the new services will be discovered and emitted automatically.