Bluetooth Low Energy Python
-
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 -
@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 -
@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".
-
C++
connect(fooWidget, &MyWidget::mySignal, barWidget, &HisWidget::mySlot);
Python;
fooWidget.mySignal.connect(barWidget.mySlot)
-
@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?
-
@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 todiscoveryAgent.start()
, if that matters. You've omitted some of theconnect
s. Theconnect
you show would bediscoveryAgent.deviceDiscovered.connect(self.addDevice)