My bluetooth adapter freezes/crashes upon sending the 2nd request (really a command as I don't handle the response) to a LE Bluetooth device (a Parrot Drone). The bluetooth icon in the Ubuntu toolbar changes to having a lock on it so the device is paired but the application just hangs when sending the 2nd request.
It's incredibly difficult to determine what is exactly going wrong. What Gattlib, Gatt, Bluez functions can I use to query the status of the bluetooth adapter, the device log and the possible cause of the freeze? Any idea what could be going wrong?
I've tried `hcidump` but nothing useful is output, it doesn't output an error/text when the adapter fails.
Below is my code that uses gattlib (GitHub - labapart/gattlib: Library to access GATT information from BLE (Bluetooth Low Energy) devices) to connect and communicate with the device. The application freezes when sending the 2nd request.
Code:
int main(int argc, char** argv)
{
gatt_connection_t* connection = gattlib_connect(NULL, MY_MAC_ADDRESS, BDADDR_LE_PUBLIC, BT_IO_SEC_LOW, 0, 0);
if (connection == NULL) {
fprintf(stderr, "Failed to connect to the bluetooth device.\n");
return 1;
}
printf("Connection Success\n\n");
// Requests
uint8_t buffer[100] = {0x01, 0x00};
int ret = gattlib_write_char_by_handle(connection, 0x00c0, buffer, sizeof(buffer));
printf("Send Cmd res %s: %d\n", (ret == 0) ? "Success":"Failed", ret);
// Outputs: "Send Cmd res Success: 0"
sleep(1); // Sleep for 1 second: incase I am flooding the device. Error occurs without sleeping aswell
// Freeze/error occurs here and the bluetooth adapter icon shows a lock on it
ret = gattlib_write_char_by_handle(connection, 0x00bd, buffer, sizeof(buffer));
printf("Send Cmd res %s: %d\n", (ret == 0) ? "Success":"Failed", ret);
sleep(1);
...
The above code is exactly the same as my `gatttool` commands which I have verified works and I can send movement commands to the drone. So I guess I can confirm it's not the drone thats the problem and that the bluetooth adapter can work when it wants to. Ie;
sudo gatttool -b XX:XX:XX:XX:XX -I
connect
char-write-req 0x00c0 0100
char-write-req 0x00bd 0100
...
Hcidump:
HCI sniffer - Bluetooth packet analyzer ver 2.5
device: hci0 snap_len: 1500 filter: 0xffffffffffffffff
- HCI Event: Command Status (0x0f) plen 4
LE Create Connection (0x08|0x000d) status 0x00 ncmd 1
- HCI Event: Command Complete (0x0e) plen 4
LE Create Connection Cancel (0x08|0x000e) ncmd 1
- HCI Event: Command Status (0x0f) plen 4
LE Create Connection (0x08|0x000d) status 0x00 ncmd 1
- HCI Event: Command Status (0x0f) plen 4
LE Connection Update (0x08|0x0013) status 0x00 ncmd 1