I am currently trying to read out Bluetooth Signals from peripherals using classic BT to control my Qt application. Later on I might use a small BT joystick but for now I am trying to connect to the buttons on my paired headphones.
I have previously
- ..scanned for remote devices via the
QBluetoothDeviceDiscoveryAgent, which returned theQBluetoothDeviceInfoof my headphones. - ...scanned for the services on that device using the
QBluetoothServiceDiscoveryAgent, which returnedQBluetoothServiceInfowithQBluetoothUuid::AV_RemoteControl ...added a socket which should connect to the device, like so:
socket0 = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol); connect(socket0, &QBluetoothSocket::stateChanged, this , &BluetoothController::socketStateChanged); connect(socket0, &QBluetoothSocket::readyRead, this, &BluetoothController::readSocket); connect(socket0, &QBluetoothSocket::connected, this, &BluetoothController::serverConnected); connect(socket0, &QBluetoothSocket::disconnected, this, &BluetoothController::serverDisconnected); connect(socket0, QOverload<QBluetoothSocket::SocketError>::of(&QBluetoothSocket::error), this, &BluetoothController::serverError); QBluetoothAddress address = info.device().address(); QIODevice::ReadOnly); socket0->connectToService(address, QBluetoothUuid::AV_RemoteControl, QIODevice::ReadOnly);At this point the socket state changes to ConnectingState, does not through an error, but also does not not trigger my
readyRead()function.
I am new to Bluetooth and may be misunderstanding the concept of how connecting exactly works, so any help will be greatly appreciated.
PS.: I am working on Linux Ubuntu 18.04 and the application log also puts out:
qt.bluetooth.bluez: Missing CAP_NET_ADMIN permission. Cannot determine whether a found address is of random or public type.
You are trying to run your software as a non-root user. The Bluetooth protocol stack for Linux checks two capabilities, which are required for operations like ones mentioned in your error log —
CAP_NET_RAWandCAP_NET_ADMIN. Capabilities are an alternative to "all or nothing" approach with privileged user (root). This gives more fine-grained control over permissions to unprivileged user so it can gain only a part of root's privileges. For more details, readman 7 capabilities.There're several techniques for leveraging capabilities, one of them are file capabilities. You can achieve the desired effect with
setcap(8)like this:sudo setcap 'cap_net_raw,cap_net_admin+eip' yourapplication