write Characteristic Result
suspend fun writeCharacteristicResult(serviceUuid: UUID, characteristicUuid: UUID, value: ByteArray): BleResult<Unit>
Writes a value to a characteristic on the connected BLE device, returning a BleResult.
This is a type-safe alternative to writeCharacteristic that returns detailed error information instead of a boolean. Use this method when you need to distinguish between different failure causes.
Usage Example
val data = "Hello".toByteArray()
connection.writeCharacteristicResult(serviceUuid, charUuid, data)
.onSuccess {
Log.i("BLE", "Write successful")
}
.onFailure { error ->
when (error) {
is BleCharacteristicException -> {
Log.e("BLE", "Write failed with GATT status: ${error.gattStatus}")
}
else -> Log.e("BLE", "Error: ${error.message}")
}
}Content copied to clipboard
Return
A BleResult containing either: - BleResult.Success with Unit indicating successful write - BleResult.Failure with a BleCharacteristicException
Parameters
service Uuid
The UUID of the GATT service containing the characteristic.
characteristic Uuid
The UUID of the characteristic to write to.
value
The ByteArray value to write to the characteristic.