labapart / gattlib

Library to access GATT information from BLE (Bluetooth Low Energy) devices
http://labapart.com/
454 stars 160 forks source link

gattlib_write_char_by_handle writing Writing more than 1 byte to char causes no return data. #72

Open frederm2010 opened 6 years ago

frederm2010 commented 6 years ago

I tried to scour the web for an answer before asking.

I have a BLE device that has one main char handle I need to write and read from.
on the Gatttool I did: [04:A3:16:A3:E9:68][LE]> char-write-req 18 0A02 Characteristic value was written successfully [04:A3:16:A3:E9:68][LE]> char-read-hnd 0x18 Characteristic value/descriptor: 01 01 00 05 00 01 01 00 05 00 01 01 00 05 00 01 01 00 05 00

Characteristic 0x18 is sent 0x10 and 0x00. This causes the return value of 20 chars which are 4 time values of 5. (yy mm dd hh mm). There are 60 total dates so I would need to make more calls to "char-write-req 18<index from 0 to 15>"

this works perfectly in the Gatttool. I am connected as PUBLIC/Low security

Using the gattlib functions I never get data back for my write to char 0x18 values ({0A,00}). some code:showing how I'm

connection = gattlib_connect(NULL, MAC, BDADDR_LE_PUBLIC, BT_SEC_LOW, 0, 0);
if (connection != NULL) {
    char ob[]{ 0x0A,0x00 }
    char buff[100]{ 0 };
        int * Len=2;
    char * GUID = "00002a1e-0000-1000-8000-00805f9b34fb";
    ret = gattlib_string_to_uuid(GUID, strlen(GUID), &srv);
    if (ret != 0) {
        ret = gattlib_write_char_by_handle(connection, 0x18, &ob, 2);
        if (ret != 0) {
            ret = gattlib_read_char_by_uuid(connection, &srv, &buff, &len);
        }
    }
}

--------------------------------GATTTOOL Working of above----------------------------- [04:A3:16:A3:E9:68][LE]> char-write-req 18 0A02 Characteristic value was written successfully [04:A3:16:A3:E9:68][LE]> char-read-hnd 0x18 Characteristic value/descriptor: 01 01 00 05 00 01 01 00 05 00 01 01 00 05 00 01 01 00 05 00

when I step thought the c++ code ret both return 0. But Len=0, and buff is all zeros.

I have another method I can call using the same characteristic 0x18. There are many. But all only send one byte. It seems that sending two bytes out is not possible when using the gattlib_write_char_byXXX.

if I do 0x18, 0x00 and then read it I get the Mac address from both Gattlib and Gatttool. if I do writeto(0x18)->1 then read(0x18) I get Time which is correct if I do writeto(0x18)->2 then read(0x18) I get device ascii name which is correct. an so on. I have 20-25 of these codes that return values. But when I try to do writeto(0x18)->0x10,0x02, and do a read(0x18) I get not returned data as mentioned above.

Has anyone seen this before? Is there something buggy in gattlib or a work around. I've written code for windows writing to these services the same way with out issue.

Any help would be appreciated.

frederm2010 commented 6 years ago

I found the Gatttool source so will see what is different.

frederm2010 commented 6 years ago

Still no luck. I must be missing something simple here.