-
Notifications
You must be signed in to change notification settings - Fork 513
Characteristic Notifying
Dariusz Seweryn edited this page Feb 2, 2018
·
4 revisions
Bluetooth standard defines two variants of peripheral induced notifications about characteristic value changes:
- Notifications
The standard way is simply broadcasting a value change of a specific characteristic. The Bluetooth specifies that only 20 bytes can be send as a notification. - Indications
Works the same as Notifications with exception that each broadcast is confirmed by the central.
It is possible that a particular characteristic supports both notifications and indications—in this situation notifications are picked.
Usage:
characteristic.monitor(
listener: (error: ?Error, characteristic: ?Characteristic) => void,
transactionId: ?TransactionId
): Subscription
or
device.monitorCharacteristicForService(
serviceUUID: UUID,
characteristicUUID: UUID,
listener: (error: ?Error, characteristic: ?Characteristic) => void,
transactionId: ?TransactionId
): Subscription
or
bleManager.monitorCharacteristicForDevice(
deviceIdentifier: DeviceId,
serviceUUID: UUID,
characteristicUUID: UUID,
listener: (error: ?Error, characteristic: ?Characteristic) => void,
transactionId: ?TransactionId
): Subscription
-
deviceIdentifier: DeviceId
—is obtained fromdevice.id
-
serviceUUID: UUID
—theUUID
of service that contains the characteristic to setup notification/indication -
characteristicUUID: UUID
—theUUID
of characteristic to setup notification/indication -
listener: (error: ?Error, characteristic: ?Characteristic) => void
—the listener for characteristic value changes. Will receive eithererror
orcharacteristic
with updated value but not both. -
transactionId: TransactionId
—optionalTransactionId
which can be used inbleManager.cancelTransaction()
function.
Note:
- Android:
- Theoretically if the notification/indication is 20 bytes long the client is responsible to issue a characteristic read afterwards to read any data that could not fit into the limit. Android does not perform the read by default
- On vanilla Android BLE API it is possible to choose wether notification or indication is setup if a characteristic supports both but the iOS does not allow to choose—that is why it is not possible to do so in this library