Characteristic
– BLE service characteristic¶
Stores information about a BLE service characteristic and allows reading and writing of the characteristic’s value.
-
class
_bleio.
Characteristic
¶ 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 byConnection.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.
Parameters: - 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:
BROADCAST
,INDICATE
,NOTIFY
,READ
,WRITE
,WRITE_NO_RESPONSE
. - 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
Attribute.NO_ACCESS
,Attribute.OPEN
,Attribute.ENCRYPT_NO_MITM
,Attribute.ENCRYPT_WITH_MITM
,Attribute.LESC_ENCRYPT_WITH_MITM
,Attribute.SIGNED_NO_MITM
, orAttribute.SIGNED_WITH_MITM
. - 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
read_perm
. - max_length (int) – Maximum length in bytes of the characteristic value. The maximum allowed is
is 512, or possibly 510 if
fixed_length
is 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.
Returns: the new Characteristic.
-
properties
¶ An int bitmask representing which properties are set, specified as bitwise or’ing of of these possible values.
BROADCAST
,INDICATE
,NOTIFY
,READ
,WRITE
,WRITE_NO_RESPONSE
.
-
uuid
¶ The UUID of this characteristic. (read-only)
Will be
None
if the 128-bit UUID for this characteristic is not known.
-
value
¶ The value of this characteristic.
-
descriptors
¶ A tuple of
Descriptor
that describe this characteristic. (read-only)
-
service
(read-only)¶ 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.
Parameters:
-
BROADCAST
¶ property: allowed in advertising packets
-
INDICATE
¶ property: server will indicate to the client when the value is set and wait for a response
-
NOTIFY
¶ property: server will notify the client when the value is set
-
READ
¶ property: clients may read this characteristic
-
WRITE
¶ property: clients may write this characteristic; a response will be sent back
-
WRITE_NO_RESPONSE
¶ property: clients may write this characteristic; no response will be sent back
-