Thread: Bluetooth Adapter Crash/Freeze on sending Request

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    4

    Bluetooth Adapter Crash/Freeze on sending Request

    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

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,980
    The example is passing 0 for "handle". Why are you passing 0x00c0 and 0x00bd?

    [edit]
    Nevermind, I just learned about handles here: Get started with Bluetooth Low Energy
    [edit]

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sending an http GET request in C
    By c++guy in forum C Programming
    Replies: 3
    Last Post: 11-04-2011, 12:42 AM
  2. Sending http get request
    By LeeVerr in forum C Programming
    Replies: 4
    Last Post: 09-07-2010, 09:02 PM
  3. Sending an http POST request
    By jaxen in forum C++ Programming
    Replies: 5
    Last Post: 11-24-2006, 12:35 PM
  4. sending https request
    By sreenu_daram in forum Networking/Device Communication
    Replies: 1
    Last Post: 08-05-2006, 09:08 AM
  5. Sending http request to httpd
    By Encrypted in forum C Programming
    Replies: 3
    Last Post: 03-30-2003, 04:57 AM

Tags for this Thread