readCharacteristic

fun readCharacteristic(serviceUuid: UUID, characteristicUuid: UUID, callback: (Int, ByteArray?) -> Unit)

Reads the value of a GATT characteristic from the connected device.

This is an asynchronous operation. The result is delivered via the callback parameter when the read completes or times out.

The state machine must be in ConnectionState.Ready for this operation to succeed. The method will look up the service and characteristic by their UUIDs from the discovered services.

A timeout is automatically applied to this operation. If the device does not respond within operationTimeoutMs, the callback will be invoked with TIMEOUT_ERROR_STATUS.

Parameters

serviceUuid

The UUID of the GATT service containing the characteristic.

characteristicUuid

The UUID of the characteristic to read.

callback

Invoked with (status, value) when the operation completes. - status: BluetoothGatt.GATT_SUCCESS on success, or an error code. - value: The characteristic value as a byte array, or null on failure.

See also

Throws

if Bluetooth permissions are not granted.