Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Bluetooth Low Energy Python
sonus89 last edited by sonus89
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:
Denni 0 Banned last edited by
Well first you would most likely need to find out if QBluetoothDeviceDiscoveryAgent class is available in PyQt5 and/or PySide2 however I would not hold my breath on that second one, but maybe it is. 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.
Basically if you can import QBluetoothDeviceDiscoveryAgent into PyQt5 I would say your golden -- you may have to pip install something first -- however you could just as easily perform all that stuff in straight python the only real thing IMO that PyQt5 can do (or should be used for) is rendering the GUI interface -- I do all the back end stuff in straight Python, C++, or C --- like talk to SQLite3, communicate with a Serial Port and the Serical Device attached to it and numerous other non-GUI related things -- and there are quite a few python libraries out there for various things
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
@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".
connect(fooWidget, &MyWidget::mySignal, barWidget, &HisWidget::mySlot);
This means that in C++:
discoveryAgent = new QBluetoothDeviceDiscoveryAgent();
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &Device::deviceScanFinished);
discoveryAgent = QtBluetooth.QBluetoothDeviceDiscoveryAgent()
Can you confirm?
JonB last edited by JonB
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
connectyou show would be
Denni 0 Banned last edited by Denni 0
Here is the documentation for that specific object
from PyQt5.QtCore import QBluetoothDeviceDiscoveryAgent self.DiscvryAgent = QBluetoothDeviceDiscoveryAgent() self.DiscvryAgent.setLowEnergyDiscoveryTimeout(5000) self.DiscvryAgent.deviceDiscovered.connect(self.AddDevice) self.DiscvryAgent.start() @pyqtSlot(object) def AddDevice(self, BlueInfo): print('Got Bluetooth Information') Note: QBluetoothDeviceInfo is what BlueInfo would be -- which can also be found here >> https://doc.qt.io/qt-5/classes.html
This needs an input parameter but I can not find it in python.
For example LowEnergyMethod