setCharacteristicValue

fun setCharacteristicValue(characteristicUUID: UUID, value: ByteArray)

Sets the value for a characteristic without sending a notification.

Use this method to update a characteristic's value that will be returned when a central device performs a read operation. Unlike sendNotification, this method does NOT push the update to subscribed devices - it only stores the value for future read requests.

When to Use

  • Use setCharacteristicValue: When you want to update a value that will be read on-demand by centrals (pull model)

  • Use sendNotification: When you want to push updates to subscribed centrals immediately (push model)

Example: Setting a Device Name Characteristic

val deviceNameUUID = UUID.fromString("00002A00-0000-1000-8000-00805f9b34fb")

// Set the device name that centrals will read
gattServer.setCharacteristicValue(
deviceNameUUID,
"My BLE Device".toByteArray(Charsets.UTF_8)
)

Parameters

characteristicUUID

The UUID of the characteristic to update

value

The new value for the characteristic

See also