Rida Shamasneh
Rida Shamasneh

Reputation: 836

Discovering specific GATT service by UUID via PyQT5 QTBluetooth module on Windows OS

I am writing a BLE client under windows using PyQT5 library. I was able to discover all services using the following snapshot of code:

        if self.controller is None:
            self.controller = QtBluetooth.QLowEnergyController.createCentral(self.currentDevice.get_device())
            self.controller.connected.connect(self.controller_connected_handler)
            self.controller.error.connect(self.controller_error_handler)
            self.controller.disconnected.connect(self.controller_disconnected_handler)
            self.controller.serviceDiscovered.connect(self.controller_service_discovered_handler)
            self.controller.discoveryFinished.connect(self.controller_discovery_finished_handler)

        if self.is_random_address():
            logging.info("Random Address")
            self.controller.setRemoteAddressType(QtBluetooth.QLowEnergyController.RandomAddress)
        else:
            logging.info("Public Address")
            self.controller.setRemoteAddressType(QtBluetooth.QLowEnergyController.PublicAddress)

        self.controller.connectToDevice()

Where "controller_service_discovered_handler" callback is executed each time a new service is discovered;

@pyqtSlot(QtBluetooth.QBluetoothUuid)
    def controller_service_discovered_handler(self, service_uuid: QtBluetooth.QBluetoothUuid):
        service = self.controller.createServiceObject(service_uuid)
        if not service:
            logging.warning('Warning: Cannot create service for uuid')
            return
        service_info = ServiceInfo(service)
        # Note that ServiceInfo is a user-defined wrapper
        logging.debug(f"New service was discovered: {service_info.serviceName} {service_info.serviceUuid}")
        self.m_services.append(service_info)

However, I wonder if "PyQT5" lib supports discovering a specific GATT service -via it's UUID- instead of discovering all the services using the callback-based approach? (I need this since some BLE device manual is suggesting the specific service discovery approach, and I need to follow the suggested flow to fix some of the issues I am currently facing)

[link to the underlying C++ QLowEnergyController implementation] https://doc.qt.io/qt-5/qlowenergycontroller.html

Upvotes: 3

Views: 475

Answers (0)

Related Questions