PySide6.QtBluetooth.QBluetoothDeviceDiscoveryAgent¶
- class QBluetoothDeviceDiscoveryAgent¶
- The - QBluetoothDeviceDiscoveryAgentclass discovers the Bluetooth devices nearby. More…- Synopsis¶- Methods¶- def - __init__()
- def - error()
- def - errorString()
- def - isActive()
 - Slots¶- Signals¶- def - canceled()
- def - deviceUpdated()
- def - errorOccurred()
- def - finished()
 - Static functions¶- 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¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - To discover the nearby Bluetooth devices: - create an instance of - QBluetoothDeviceDiscoveryAgent,
- connect to either the - deviceDiscovered()or- finished()signals,
- and call - start().
 - def startDeviceDiscovery(self): # Create a discovery agent and connect to its signals discoveryAgent = QBluetoothDeviceDiscoveryAgent(self) connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)), self, SLOT(deviceDiscovered(QBluetoothDeviceInfo))) # Start a discovery discoveryAgent.start() #... # In your local slot, read information about the found devices def deviceDiscovered(self, device): print("Found device():", device.name(), '(', device.address().toString(), ')') - To retrieve results asynchronously, connect to the - deviceDiscovered()signal. To get a list of all discovered devices, call- discoveredDevices()after the- finished()signal.- This class can be used to discover Classic and Low Energy Bluetooth devices. The individual device type can be determined via the - coreConfigurations()attribute. In most cases the list returned by- discoveredDevices()contains both types of devices. However not every platform can detect both types of devices. On platforms with this limitation (for example iOS only suports Low Energy discovery), the discovery process will limit the search to the type which is supported.- Note - Since Android 6.0 the ability to detect devices requires ACCESS_COARSE_LOCATION. - Note - The Win32 backend currently does not support the Received Signal Strength Indicator (RSSI), as well as the Manufacturer Specific Data, or other data updates advertised by Bluetooth LE devices after discovery. - class Error¶
- Indicates all possible error conditions found during Bluetooth device discovery. - Constant - Description - QBluetoothDeviceDiscoveryAgent.NoError - No error has occurred. - QBluetoothDeviceDiscoveryAgent.PoweredOffError - The Bluetooth adaptor is powered off, power it on before doing discovery. - QBluetoothDeviceDiscoveryAgent.InputOutputError - Writing or reading from the device resulted in an error. - QBluetoothDeviceDiscoveryAgent.InvalidBluetoothAdapterError - The passed local adapter address does not match the physical adapter address of any local Bluetooth device. - QBluetoothDeviceDiscoveryAgent.UnsupportedPlatformError - Device discovery is not possible or implemented on the current platform. The error is set in response to a call to - start(). An example for such cases are iOS versions below 5.0 which do not support Bluetooth device search at all.- QBluetoothDeviceDiscoveryAgent.UnsupportedDiscoveryMethod - One of the requested discovery methods is not supported by the current platform. - QBluetoothDeviceDiscoveryAgent.LocationServiceTurnedOffError - The location service is turned off. Usage of Bluetooth APIs is not possible when location service is turned off. - QBluetoothDeviceDiscoveryAgent.MissingPermissionsError - The operating system requests permissions which were not granted by the user. - QBluetoothDeviceDiscoveryAgent.UnknownError - An unknown error has occurred. 
 - class DiscoveryMethod¶
- (inherits - enum.Flag) This enum descibes the type of discovery method employed by the- QBluetoothDeviceDiscoveryAgent.- Constant - Description - QBluetoothDeviceDiscoveryAgent.NoMethod - The discovery is not possible. None of the available methods are supported. - QBluetoothDeviceDiscoveryAgent.ClassicMethod - The discovery process searches for Bluetooth Classic (BaseRate) devices. - QBluetoothDeviceDiscoveryAgent.LowEnergyMethod - The discovery process searches for Bluetooth Low Energy devices. - See also 
 - Constructs a new Bluetooth device discovery agent with parent - parent.- __init__(deviceAdapter[, parent=None])
- Parameters:
- deviceAdapter – - QBluetoothAddress
- parent – - QObject
 
 
 - Constructs a new Bluetooth device discovery agent with - parent.- It uses - deviceAdapterfor the device search. If- deviceAdapteris default constructed the resulting- QBluetoothDeviceDiscoveryAgentobject will use the local default Bluetooth adapter.- If a - deviceAdapteris specified that is not a local adapter- error()will be set to- InvalidBluetoothAdapterError. Therefore it is recommended to test the error flag immediately after using this constructor.- See also - canceled()¶
 - This signal is emitted when device discovery is aborted by a call to - stop().- deviceDiscovered(info)¶
- Parameters:
- info – - QBluetoothDeviceInfo
 
 - This signal is emitted when the Bluetooth device described by - infois discovered.- The signal is emitted as soon as the most important device information has been collected. However, as long as the - finished()signal has not been emitted the information collection continues even for already discovered devices. This is particularly true for signal strength information (RSSI) and manufacturer data updates. If the use case requires continuous manufacturer data or RSSI updates it is advisable to retrieve the device information via- discoveredDevices()once the discovery has finished or listen to the- deviceUpdated()signal.- If - lowEnergyDiscoveryTimeout()is larger than 0 the signal is only ever emitted when at least one attribute of- infochanges. This reflects the desire to receive updates as more precise information becomes available. The exception to this behavior is the case when- lowEnergyDiscoveryTimeoutis set to- 0. A timeout of- 0expresses the desire to monitor the appearance and disappearance of Low Energy devices over time. Under this condition the deviceDiscovered() signal is emitted even if- infohas not changed since the last signal emission.- See also - deviceUpdated(info, updatedFields)¶
- Parameters:
- info – - QBluetoothDeviceInfo
- updatedFields – Combination of - Field
 
 
 - This signal is emitted when the agent receives additional information about the Bluetooth device described by - info. The- updatedFieldsflags tell which information has been updated.- During discovery, some information can change dynamically, such as - signal strengthand- manufacturerData. This signal informs you that if your application is displaying this data, it can be updated, rather than waiting until the discovery has finished.- See also - discoveredDevices()¶
- Return type:
- .list of QBluetoothDeviceInfo 
 
 - Returns a list of all discovered Bluetooth devices. - Returns the last error. - Any possible previous errors are cleared upon restarting the discovery. - This signal is emitted when an - erroroccurs during Bluetooth device discovery. The- errorparameter describes the error that occurred.- See also - errorString()¶
- Return type:
- str 
 
 - Returns a human-readable description of the last error. - See also - finished()¶
 - This signal is emitted when Bluetooth device discovery completes. The signal is not going to be emitted if the device discovery finishes with an error. - isActive()¶
- Return type:
- bool 
 
 - Returns true if the agent is currently discovering Bluetooth devices, otherwise returns false. - lowEnergyDiscoveryTimeout()¶
- Return type:
- int 
 
 - Returns a timeout in milliseconds that is applied to the Bluetooth Low Energy device search. A value of - -1implies that the platform does not support this property and the timeout for the device search cannot be adjusted. A return value of- 0implies a never-ending search which must be manually stopped via- stop().- See also - setLowEnergyDiscoveryTimeout(msTimeout)¶
- Parameters:
- msTimeout – int 
 
 - Sets the maximum search time for Bluetooth Low Energy device search to - timeoutin milliseconds. If- timeoutis- 0the discovery runs until- stop()is called.- This reflects the fact that the discovery process for Bluetooth Low Energy devices is mostly open ended. The platform continues to look for more devices until the search is manually stopped. The timeout ensures that the search is aborted after - timeoutmilliseconds. Of course, it is still possible to manually abort the discovery by calling- stop().- The new timeout value does not take effect until the device search is restarted. In addition the timeout does not affect the classic Bluetooth device search. Depending on the platform the classic search may add more time to the total discovery process beyond - timeout.- For a reliable Bluetooth Low Energy discovery, use at least 40000 milliseconds. - See also - start()¶
 - Starts Bluetooth device discovery, if it is not already started. - The - deviceDiscovered()signal is emitted as each device is discovered. The- finished()signal is emitted once device discovery is complete. The discovery utilizes the maximum set of supported discovery methods on the platform.- See also - start(method)
- Parameters:
- method – Combination of - DiscoveryMethod
 
 - Starts Bluetooth device discovery, if it is not already started and the provided - methodsare supported. The discovery- methodslimit the scope of the device search. For example, if the target service or device is a Bluetooth Low Energy device, this function could be used to limit the search to Bluetooth Low Energy devices and thereby reduces the discovery time significantly.- Note - methodsonly determines the type of discovery and does not imply the filtering of the results. For example, the search may still contain classic bluetooth devices despite- methodsbeing set to- LowEnergyMethodonly. This may happen due to previously cached search results which may be incorporated into the search results.- stop()¶
 - Stops Bluetooth device discovery. The cancel() signal is emitted once the device discovery is canceled. - start()maybe called before the cancel signal is received. Once- start()has been called the cancel signal from the prior discovery will be discarded.- static supportedDiscoveryMethods()¶
- Return type:
- Combination of - DiscoveryMethod
 
 - This function returns the discovery methods supported by the current platform. It can be used to limit the scope of the device discovery.