Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to get bluetooth socket of already connected device?



  • Hello.

    I have a problem with connecting to bluetooth devices with Qt. I'm testing the blood pressure monitor device which is sending data via Bluetooth. You can pair with the device and I have done this in my Qt application and it works fine. When the device is already paired and you power it on, it's measuring the blood pressure and connecting to the paired device automatically. So I connected signals deviceConnected and deviceDisconnected from QBluetoothLocalDevice class and it works as expected, I get the logs from their corresponding slots. My problem is, that I need to read the measured data from the device, but don't know how to do it. Normally I would just connect to the device with QBluetoothSocket class, where I have methods like readyRead(), readAll() etc. or I can write to the device some commands. But how can I do this when the device connects, and I have already established connection? Can I somehow create and attach a QBluetoothSocket to the existing connection or something like that? Because in QBluetoothLocalDevice class I can't see any functions to read or write to the device.

    The second problem I have is with a weight scale which sends data via Bluetooth Low Energy. I managed to create app that pairs to the device, and can read characteristics from it using QLowEnergyController and QLowEnergyService classes. Right now, after measurement, the scale is sending the data to the paired device, and I tried the same approach as with blood pressure monitor to connect deviceConnected() and deviceDisconnected() signals to slots but they are not called when the device is sending so I assume it doesn't automatically connects. So you have to manually click the connect button every time the scale is sending data and every time it discovers the services and characteristic from the device which I feel is not a very nice solution. So my question is: Can I connect to the BLE device more elegant way, so once the device are paired, when the scale is sending me data, it connects automatically?

    Thanks for the help.


Log in to reply