Understanding BlueZ for HID bluetooth


New Member
I want to use a RPi4 with Raspbian GNU/Linux 10 (buster) as bluetooth HID device.

The bluetooth pairing works fine as long as I not load my Java app. At the startup my Java app uses the BlueCove lib to start a "btspp" server with the HID service (1124). I got no exception from Java and no error from the sddb at setup. With "sdptool" a can see the HID service running at the sddb.

But when I try to pair my RPi4 with a client PC after startup of my app the connection is refused right after the beginning. I added the system log (btlog.txt) of the pairing process which shows the errors but I do not understand the error ids and I cannot find a error id description.

I assume there is a mistake in the HID service attributes settings my app defines but after reviewing specs and examples I cannot find a obvious problem. I added my Java bluetooth class with the attribute constants and the HID descriptors.

Has someone a hint?



New Member
I found a possible problem, but have no solution upto now. It looks like to be an encoding issue.

As the spec defines the Hid descriptor item should be a "string attribute type with unsigned int8 elements". Therefore I wrote this codesnippet to convert my descriptor (checked and tested for correctness) from a Byte list to the needed string format:

StringBuilder btHIDDescriptor_Data = new StringBuilder();
ArrayList<Byte> report = HidWorkbench.parseDatFormat(new BufferedReader(new FileReader(reportDatFile)));
report.forEach(bElement -> {
btHIDDescriptor.addElement(new DataElement(DataElement.STRING, btHIDDescriptor_Data.toString()));
The HID report descriptor from my file "mediaMouseRepDesc" for example looks like:

The strange issue I found and don't understand is the readback from the sddb. If I read the service back from the sddb in xml format I get:

In addition to the expected values there are bytes in the string I cannot determine. I don't get a pattern or meaning behind it. My Java application says the string ist exact as long as the byte list is. That let me assume that it's an encoding issue, but what encoding is expected here?


New Member
I tested the string conversion with different encoding constraints (UTF-8, US_ASCII, ISO-8859-1 and so on). All encoding types leads to the same fault in different variations.
If the byte value is negativ, all encodings add different bytes with different values in front of it.
It seems not to be possible to generate a string with Java that contains really only single-byte-characters.

But this would imply a strange design fault in the BlueCove lib.
The constructor new DataElement(DataElement.STRING, reportString) only accepts strings. Other types like byte[] or char[] throw a illegal argument exception. I must use strings but any Java string in every type is misinterpreted.

So I don't know how the report descriptor configuration with this lib should work.

This leads to my initial question. Due to the issue I do not understand the error log I do not know if this descriptor issue is really the problem.
Last edited:
$100 Digital Ocean Credit
Get a free VM to test out Linux!