-
Notifications
You must be signed in to change notification settings - Fork 516
Characteristic Writing
There are two currently supported ways to write a characteristic:
This is the default way of writing characteristics (sometimes referred as a Write Request
). It consists of a Write Request
and a following Write Response
indicating wether the write has been accepted by the peripheral.
characteristic.writeWithResponse(
valueBase64: Base64,
transactionId: ?TransactionId
): Promise<Characteristic>
or
device.writeCharacteristicWithResponseForService(
serviceUUID: UUID,
characteristicUUID: UUID,
valueBase64: Base64,
transactionId: ?TransactionId
): Promise<Characteristic>
or
bleManager.writeCharacteristicWithResponseForDevice(
deviceIdentifier: DeviceId,
serviceUUID: UUID,
characteristicUUID: UUID,
base64Value: Base64,
transactionId: ?TransactionId
): Promise<Characteristic>
-
deviceIdentifier: DeviceId
—is obtained fromdevice.id
-
serviceUUID: UUID
—theUUID
of service that contains the characteristic to write -
characteristicUUID: UUID
—theUUID
of characteristic to write -
base64Value: Base64
—Value in Base64 format. -
transactionId: TransactionId
—optionalTransactionId
which can be used inbleManager.cancelTransaction()
function
The resulting Promise emits this characteristic when the response is received. Latest value may not be stored inside returned object.
Unlike the above write type this one does not induce a Write Response
from the peripheral (therefore it is sometimes referred as a Write Command
). Not all peripherals/characteristics support this type of write. It is generally faster to send more data to the peripheral but in expense of loosing the ability to know if the peripheral is able to process the bulk of data (it is peripheral's responsibility to control the flow).
characteristic.writeWithoutResponse(
valueBase64: Base64,
transactionId: ?TransactionId
): Promise<Characteristic>
or
device.writeCharacteristicWithoutResponseForService(
serviceUUID: UUID,
characteristicUUID: UUID,
valueBase64: Base64,
transactionId: ?TransactionId
): Promise<Characteristic>
or
bleManager.writeCharacteristicWithoutResponseForDevice(
deviceIdentifier: DeviceId,
serviceUUID: UUID,
characteristicUUID: UUID,
base64Value: Base64,
transactionId: ?TransactionId
): Promise<Characteristic>
-
deviceIdentifier: DeviceId
—is obtained fromdevice.id
-
serviceUUID: UUID
—theUUID
of service that contains the characteristic to write -
characteristicUUID: UUID
—theUUID
of characteristic to write -
base64Value: Base64
—Value in Base64 format. -
transactionId: TransactionId
—optionalTransactionId
which can be used inbleManager.cancelTransaction()
function
The resulting Promise emits this {@link Characteristic} when the request is queued. Latest value may not be stored inside returned object.
Note:
- iOS—on older devices writes without response were queued on an internal buffer of size ~10. When this buffer was full some writes could be dropped without notice
- Android—on older devices (<5.0) writes without response were queued on an internal buffer of size ~100. When this buffer was full a write command was being dropped an no callback was received (
BleGattCallbackTimeoutException
). Usually in this situation retrying was enough to get the writing on track unless a disconnection has happened when the buffer was not empty—this should not be a problem though since theRxAndroidBle
always closes theBluetoothGatt
on disconnection