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 the QBluetoothDeviceInfo of my headphones.
...scanned for the services on that device using the QBluetoothServiceDiscoveryAgent, which returned QBluetoothServiceInfo with QBluetoothUuid::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_RAW and CAP_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, read man 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
Related
The situation is as follows: I have a piece of hardware connected to a, windows running, PC via a serial port. This custom hardware is used to interface other hardware through GPIB. Now, the software that is used to operate this setup on the PC side needs to be changed without touching the hardware in the middle. The problem is getting a hold of the proper serial comm. parameters used for communication - setting them (the timeouts in particular - baud rates and bits are fine) to arbitrary values in the new software leads to a lot of comm errors so I'd like to know them precisely. The function GetCommTimeouts() would do the job, however you need the handle to the comm. device aquired via call to CreateFile() - only the original software has access to it. So the question is if one can get a hold of these settings from outside of the running, old app?
Thanks,
drinker
I would suggest using a tool like Process Monitor. This tool can monitor the calls that are used to open and configure a serial port.
I am writing an application for LPC4330 microcontroller, that will allow the user to update the firmware using USB DFU class. I wrote all of the code and I wanted to test it using dfu-util software. But when I try to do it few errors appear:
When I list the USB devices, two elements with the same parameters (vendor id, device id, configuration and interface) appear. The situation changes when I make a breakpoint in the application, in place where interrupt process function is called. Then only one device appears on the list.
I cannot detach the device because I get error "No USB device is DFU capable". Even when only one device is listed by dfu-util.
When only one device is listed I can start performing upload/download operation, but the application sends me an error, that interface cannot be claimed.
What could be a reason of these problems? Could it be connected with LPC4330 feature allowing user to flash the programme to the memory using dfu?
Thank you in advance for your answer!
You write your own DFU that is fine. Can I get to know from which mode you are trying to do firmware upgrade? Like downstream or upstream.
And if you are trying from any one of the mode please make sure that you are creating the device for particular mode only.
Detach will work, only when your DFU should have in run time mode. So please make sure that you are in run time mode or DFU mode. And before Detach try to reset your device by using software command
I have a device without knowing the used gatt profile, I only know that is something "homemade" and not anything known on the bluetooth-database.
In Linux the command
gatttool -i hci0 -b xx:xx:xx:xx:xx:xx --char-read --handle=42
returns the value as expected (with the target device mac at xx:xx:xx:xx:xx:xx).
In Qt I am using the Heartbeat-Example from http://doc-snapshot.qt-project.org/qt5-5.4/qtbluetooth-heartlistener-example.html
there they connect using a gattprofile, QBluetoothUuid::HeartRate and QBluetoothUuid::HeartRateMeasurement
I wasn't able to modify the example code in a way to read handle 42.
Can you explain where I have to put which values, that it connects to the "standard profile" as the gattool command does? If I use gatttool in interactive mode and ask primary it returns two uuids, but using them instead of the QBluetoothUuid::HeartRate did not work.
It doesn't appear that the Qt Bluetooth Low Energy API provides means for obtaining access to characteristics based on their handle value. (Neither does the Windows 8 BLE API.) You should use the UUID. Even if it's a homemade device, all services and characteristics are required by the GATT protocol to have UUIDs. The lowenergyscanner demo app can discover and display both the UUIDs and handles of all of the device's services and characteristics. I've used lowenergyscanner to deal with BLE devices I'm developing.
device discovering is by uuid, even if you create a new profile with a new service and a new characteristic, you have to give the new characteristic uuid in setup.
But i dont know, how to add multiple characteristics to one service, it does not work with me.
have fun
I want to implement WiFi manager program which should handle the following.
notification on wi-fi access point has come or gone
provide information of available wifi access point
connect/disconnect with a given wi-fi access point
Which is the recommended C/C++ WiFi library for Linux to achieve this?
On Fedora (at least), the preferred way to interact with NetworkManager is via DBus.
While wireless-tools and the like will work — even direct kernel calls, if you must — there are a couple of problems:
You'll probably need superuser privileges
NetworkManager will probably have a panic attack and get into fights with you, unless you stop its service
The user's normal networking controls (e.g. desktop tray icons) are almost certainly configured to use NetworkManager.
You can send and receive DBus messages for all the tasks you mentioned, for WiFi as well as arbitrary other types of network interfaces. The API is published here, for version 0.8.
For newer operating systems, there are apparently changes in the API, with a migration guide.
Their wiki should be really helpful.
I know both Fedora and Ubuntu use NetworkManager by default; I believe many other systems do, as well, but don't have an exhaustive list.
Of course, if you're using an embedded system, custom distribution, or something, then your mileage may vary.
That would be wireless-tools
I would recommend using directly the NetworkManager Library.
You can use low-level D-Bus library or libnm-glib library, that makes communication easier: example add connection glib
For more info, you can take a look into the code of the command line client nmcli.
I read some questions here but couldn't really find the specific problem I'am faced with here...
I need to implement a "DeviceCache" in a particular project which caches all device-names found in /proc/net/dev .
The Language is C/++
So I thought about a seperate thread looking every X seconds in the directory mentioned above but was encouraged to find a more direct way.
How can I register a method of my process to the device manager of linux?
Is there a similar way like events/signals?
I looked in other sites but couldn't find any helpful code... Im relatively new to Linux-programming but willing to learn new things :)
Based on your comments, what you really want is to track which network interfaces are operational at any given time.
The only true way to determine if a network interface is up is to test it - after all, the router on the other end may be down. You could send pings out periodically, for example.
However, if you just want to know if the media goes down (ie, the network cable is unplugged), take a look at these SO questions:
Linux carrier detection notification
Get notified about network interface change on Linux
If you just want to be notified of the actual hardware-level registration of interfaces (eg, when a USB NIC is plugged in), you can use udev events if your platform has udev; otherwise, I believe there's another netlink category for hardware addition/removal events.