Characteristic – BLE service characteristic¶
Stores information about a BLE service characteristic and allows reading and writing of the characteristic’s value.
There is no regular constructor for a Characteristic. A new local Characteristic can be created and attached to a Service by calling
add_to_service(). Remote Characteristic objects are created by
Connection.discover_remote_services()as part of remote Services.
add_to_service(service, uuid, *, properties=0, read_perm=Attribute.OPEN, write_perm=Attribute.OPEN, max_length=20, fixed_length=False, initial_value=None)¶
Create a new Characteristic object, and add it to this Service.
- service (Service) – The service that will provide this characteristic
- uuid (UUID) – The uuid of the characteristic
- properties (int) – The properties of the characteristic,
specified as a bitmask of these values bitwise-or’d together:
- read_perm (int) – Specifies whether the characteristic can be read by a client, and if so, which
security mode is required. Must be one of the integer values
- write_perm (int) – Specifies whether the characteristic can be written by a client, and if so, which
security mode is required. Values allowed are the same as
- max_length (int) – Maximum length in bytes of the characteristic value. The maximum allowed is
is 512, or possibly 510 if
fixed_lengthis False. The default, 20, is the maximum number of data bytes that fit in a single BLE 4.x ATT packet.
- fixed_length (bool) – True if the characteristic value is of fixed length.
- initial_value (buf) – The initial value for this characteristic. If not given, will be filled with zeros.
the new Characteristic.
The UUID of this characteristic. (read-only)
Noneif the 128-bit UUID for this characteristic is not known.
The value of this characteristic.
The Service this Characteristic is a part of.
set_cccd(*, notify=False, indicate=False)¶
Set the remote characteristic’s CCCD to enable or disable notification and indication.
property: allowed in advertising packets
property: server will indicate to the client when the value is set and wait for a response
property: server will notify the client when the value is set
property: clients may read this characteristic
property: clients may write this characteristic; a response will be sent back
property: clients may write this characteristic; no response will be sent back