write
abstract suspend fun write(data: ByteArray, writeType: WriteType = properties.defaultWriteType ?: WriteType.WITH_RESPONSE)
Writes the value of the characteristic.
If data is longer than Peripheral.maximumWriteValueLength for given writeType, the value will be trimmed. To write longer values, chunked them and write subsequent chunks.
val data: ByteArray = // ...
val maxLength = peripheral.maximumWriteValueLength(WriteType.WITHOUT_RESPONSE)
data.chunked(maxLength).forEach { chunk ->
remoteCharacteristic.write(chunk, WriteType.WITHOUT_RESPONSE)
}Content copied to clipboard
Parameters
data
The data to be written.
writeType
The write type to be used. By default, it is set to the characteristic's default write type based on its properties.
Throws
if the value was sent using Long Write or Reliable Write procedure and the value replied back by the peripheral does not match the value written.
if the operation failed.
if the characteristic has been invalidated due to disconnection or service change event.
if the implementation fails, see BluetoothException.cause for a reason.