- class QLowEnergyCharacteristic#
The
QLowEnergyCharacteristic
class stores information about a Bluetooth Low Energy service characteristic. More…Synopsis#
Methods#
def
__init__()
def
descriptor()
def
descriptors()
def
isValid()
def
name()
def
__ne__()
def
__eq__()
def
properties()
def
uuid()
def
value()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
QLowEnergyCharacteristic
provides information about a Bluetooth Low Energy service characteristic’sname()
,uuid()
,value()
,properties()
, anddescriptors()
. To obtain the characteristic’s specification and information, it is necessary to connect to the device using theQLowEnergyService
andQLowEnergyController
classes.The characteristic value may be written via the
QLowEnergyService
instance that manages the service to which this characteristic belongs. ThewriteCharacteristic()
function writes the new value. ThecharacteristicWritten()
signal is emitted upon success. Thevalue()
of this object is automatically updated accordingly.Characteristics may contain none, one or more descriptors. They can be individually retrieved using the
descriptor()
function. Thedescriptors()
function returns all descriptors as a list. The general purpose of a descriptor is to add contextual information to the characteristic. For example, the descriptor might provide format or range information specifying how the characteristic’s value is to be interpreted.See also
- class PropertyType#
(inherits
enum.Flag
) This enum describes the properties of a characteristic.Constant
Description
QLowEnergyCharacteristic.Unknown
The type is not known.
QLowEnergyCharacteristic.Broadcasting
Allow for the broadcasting of Generic Attributes (GATT) characteristic values.
QLowEnergyCharacteristic.Read
Allow the characteristic values to be read.
QLowEnergyCharacteristic.WriteNoResponse
Allow characteristic values without responses to be written.
QLowEnergyCharacteristic.Write
Allow for characteristic values to be written.
QLowEnergyCharacteristic.Notify
Permits notification of characteristic values.
QLowEnergyCharacteristic.Indicate
Permits indications of characteristic values.
QLowEnergyCharacteristic.WriteSigned
Permits signed writes of the GATT characteristic values.
QLowEnergyCharacteristic.ExtendedProperty
Additional characteristic properties are defined in the characteristic’s extended properties descriptor.
It is not recommended to set both Notify and Indicate properties on the same characteristic as the underlying Bluetooth stack behaviors differ from platform to platform. Please see
clientCharacteristicConfiguration
See also
- PySide6.QtBluetooth.QLowEnergyCharacteristic.CCCDDisable#
- PySide6.QtBluetooth.QLowEnergyCharacteristic.CCCDEnableNotification#
- PySide6.QtBluetooth.QLowEnergyCharacteristic.CCCDEnableIndication#
- __init__()#
Construct a new
QLowEnergyCharacteristic
. A default-constructed instance of this class is always invalid.See also
- __init__(other)
- Parameters:
other –
QLowEnergyCharacteristic
Construct a new
QLowEnergyCharacteristic
that is a copy ofother
.The two copies continue to share the same underlying data which does not detach upon write.
- clientCharacteristicConfiguration()#
- Return type:
Returns the Client Characteristic Configuration Descriptor or an invalid
QLowEnergyDescriptor
instance if no Client Characteristic Configuration Descriptor exists.BTLE characteristics can support notifications and/or indications. In both cases, the peripheral will inform the central on each change of the characteristic’s value. In the BTLE attribute protocol, notification messages are not confirmed by the central, while indications are confirmed. Notifications are considered faster, but unreliable, while indications are slower and more reliable.
If a characteristic supports notification or indication, these can be enabled by writing special bit patterns to the Client Characteristic Configuration Descriptor. For convenience, these bit patterns are provided as QLowEnergyCharacteristic::CCCDDisable , QLowEnergyCharacteristic::CCCDEnableNotification , and QLowEnergyCharacteristic::CCCDEnableIndication .
Enabling e.g. notification for a characteristic named
mycharacteristic
in a service calledmyservice
could be done using the following code.auto cccd = mycharacteristic.clientCharacteristicConfiguration(); if (!cccd.isValid()) { // your error handling return error; } myservice->writeDescriptor(cccd, QLowEnergyCharacteristic::CCCDEnableNotification);
Note
Calling
characteristic.clientCharacteristicConfiguration()
is equivalent to callingcharacteristic.descriptor(QBluetoothUuid::DescriptorType::ClientCharacteristicConfiguration)
.Note
It is not recommended to use both notifications and indications on the same characteristic. This applies to both server-side when setting up the characteristics, as well as client-side when enabling them. The bluetooth stack behavior differs from platform to platform and the cross-platform behavior will likely be inconsistent. As an example a Bluez Linux client might unconditionally try to enable both mechanisms if both are supported, whereas a macOS client might unconditionally enable just the notifications. If both are needed consider creating two separate characteristics.
See also
- descriptor(uuid)#
- Parameters:
uuid –
QBluetoothUuid
- Return type:
Returns the descriptor for
uuid
or an invalidQLowEnergyDescriptor
instance.See also
- descriptors()#
- Return type:
.list of QLowEnergyDescriptor
Returns the list of descriptors belonging to this characteristic; otherwise an empty list.
See also
- isValid()#
- Return type:
bool
Returns
true
if theQLowEnergyCharacteristic
object is valid, otherwise returnsfalse
.An invalid characteristic object is not associated with any service (default-constructed) or the associated service is no longer valid due to a disconnect from the underlying Bluetooth Low Energy device, for example. Once the object is invalid it cannot become valid anymore.
Note
If a
QLowEnergyCharacteristic
instance turns invalid due to a disconnect from the underlying device, the information encapsulated by the current instance remains as it was at the time of the disconnect. Therefore it can be retrieved after the disconnect event.- name()#
- Return type:
str
Returns the human-readable name of the characteristic.
The name is based on the characteristic’s
uuid()
which must have been standardized. The complete list of characteristic types can be found under Bluetooth.org Characteristics .The returned string is empty if the
uuid()
is unknown.See also
- __ne__(b)#
- Parameters:
- Return type:
bool
Returns
true
ifa
andb
are not equal; otherwisefalse
.Two QLowEnergyCharcteristic instances are considered to be equal if they refer to the same characteristic on the same remote Bluetooth Low Energy device or both instances have been default-constructed.
- __eq__(b)#
- Parameters:
- Return type:
bool
Returns
true
ifa
is equal tob
, otherwisefalse
.Two
QLowEnergyCharacteristic
instances are considered to be equal if they refer to the same characteristic on the same remote Bluetooth Low Energy device or both instances have been default-constructed.- properties()#
- Return type:
Combination of
PropertyType
Returns the properties of the characteristic.
The properties define the access permissions for the characteristic.
- uuid()#
- Return type:
Returns the UUID of the characteristic if
isValid()
returnstrue
; otherwise a null UUID.- value()#
- Return type:
Returns the cached value of the characteristic.
If the characteristic’s
properties()
permit writing of new values, the value can be updated usingwriteCharacteristic()
.The cache is updated during the associated service’s
detail discovery
, a successfulread
/write
operation or when an update notification is received.The returned QByteArray always remains empty if the characteristic does not have the
read permission
. In such cases only thecharacteristicChanged()
orcharacteristicWritten()
may provice information about the value of this characteristic.