Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Bluetooth Low Energy Python
QtWS25 Last Chance

Bluetooth Low Energy Python

Scheduled Pinned Locked Moved Solved Qt for Python
7 Posts 4 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sonus89
    wrote on last edited by sonus89
    #1

    Hi there,
    I can only find C++ examples for Bluetooth Low Energy on Windows.
    It is not easy to convert the C++ code into Python.
    Are there any BLE examples for PyQt? ( scan, connect, notify, write....etc. ) Basic methods needed.

    Or at least... could somebody tell the pythonic version of the first sample - Scan Devices here:
    https://doc.qt.io/qt-5/qtbluetooth-lowenergyscanner-example.html

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Denni-0 said in Bluetooth Low Energy Python:

      There are elements (if I understood their statements) of Qt5 that have not been ported to PyQt5 (which is the most complete of the 2 options) due to Qt not sharing those items openly but that could have been old news or new news or misunderstood/misquoted news -- not sure.

      What statements are you talking about ?
      The QtConnectivity module which provides Bluetooth support is available: https://code.qt.io/cgit/qt/qtconnectivity.git

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Offline
        S Offline
        sonus89
        wrote on last edited by
        #3

        @Denni-0 Everything works fine in PyQt5. I could import the modules and I am half way done with converting C++ sample code into Python. However I am stuck at the "connect" method... I was curious if these codelines already exist somewhere in Python.

        So the question is not "if it works in Python" the question was "how to convert the C++ example into Python".

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          C++

          connect(fooWidget, &MyWidget::mySignal, barWidget, &HisWidget::mySlot);
          

          Python;

          fooWidget.mySignal.connect(barWidget.mySlot)
          

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          1
          • SGaistS SGaist

            C++

            connect(fooWidget, &MyWidget::mySignal, barWidget, &HisWidget::mySlot);
            

            Python;

            fooWidget.mySignal.connect(barWidget.mySlot)
            
            S Offline
            S Offline
            sonus89
            wrote on last edited by
            #5

            @SGaist Thanks!

            This means that in C++:

            discoveryAgent = new QBluetoothDeviceDiscoveryAgent();
            discoveryAgent->setLowEnergyDiscoveryTimeout(5000);
            connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered,
            this, &Device::addDevice);
            connect(discoveryAgent, QOverloadQBluetoothDeviceDiscoveryAgent::Error::of(&QBluetoothDeviceDiscoveryAgent::error),
            this, &Device::deviceScanError);
            connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &Device::deviceScanFinished);
            discoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);

            In Python:

            discoveryAgent = QtBluetooth.QBluetoothDeviceDiscoveryAgent()
            discoveryAgent.setLowEnergyDiscoveryTimeout(5000)
            discoveryAgent.deviceDiscovered.connect(addDevice)
            discoveryAgent.start()

            Can you confirm?

            JonBJ 1 Reply Last reply
            0
            • S sonus89

              @SGaist Thanks!

              This means that in C++:

              discoveryAgent = new QBluetoothDeviceDiscoveryAgent();
              discoveryAgent->setLowEnergyDiscoveryTimeout(5000);
              connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered,
              this, &Device::addDevice);
              connect(discoveryAgent, QOverloadQBluetoothDeviceDiscoveryAgent::Error::of(&QBluetoothDeviceDiscoveryAgent::error),
              this, &Device::deviceScanError);
              connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &Device::deviceScanFinished);
              discoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);

              In Python:

              discoveryAgent = QtBluetooth.QBluetoothDeviceDiscoveryAgent()
              discoveryAgent.setLowEnergyDiscoveryTimeout(5000)
              discoveryAgent.deviceDiscovered.connect(addDevice)
              discoveryAgent.start()

              Can you confirm?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @sonus89
              That's more or less right, I don't know how exact you want the answer to be. You're not passing the argument to discoveryAgent.start(), if that matters. You've omitted some of the connects. The connect you show would be

              discoveryAgent.deviceDiscovered.connect(self.addDevice)
              
              1 Reply Last reply
              1
              • S Offline
                S Offline
                sonus89
                wrote on last edited by
                #7

                @Denni-0 Thanks!

                self.DiscvryAgent.start()

                This needs an input parameter but I can not find it in python.
                For example LowEnergyMethod

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved