Error in writing the BLE characteristic data from Linux Bleak library to the nimble stack running on esp32.

ujurmsde
Posts: 38
Joined: Tue Jan 19, 2021 6:37 am

Error in writing the BLE characteristic data from Linux Bleak library to the nimble stack running on esp32.

Postby ujurmsde » Wed Oct 12, 2022 7:22 pm

I have a code, which basically has three characteristic which has read/write attributes. I am using Linux Bluez along with Bleak python library to send some data from my laptop to the esp32 but there seems to be an error receiving the data.

The error is not on the Bleak side as I have analysed the Bluetooth Wireshark logs and also asked the question on github page.
https://github.com/hbldh/bleak/issues/1075

My question is that what could be wrong in my code which prevent writing from Linux laptop? As I have no clue right now what can be wrong. What is even more is that I can write to the characteristic via apps like nRF connect.

So Let me post the snipate of the code I have running on esp. In the gatt_callback() function I have following code to receive and send ble gatt values.

Code: Select all

//global scope
static uint8_t received_val;

//function scope
void *dest= &received_val;   

 if(ble_uuid_cmp(uuid, &gatt_server_rgb_red_characteristic_uuid.u) == 0)
    {
        if(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR){
        rc = os_mbuf_append(ctxt->om, &rand_num, sizeof(rand_num));
        return rc;
        }
        
        if(ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR){
        rc = ble_hs_mbuf_to_flat(ctxt->om, dest, sizeof received_val, NULL);
        printf("Received %d", received_val);
        r = received_val;
        ESP_LOGI("TAG", "Write the char");
            
        if (rc != 0)
        {
            return BLE_ATT_ERR_UNLIKELY;
        }
        }
    }
  
The error I get on the command prompt while trying to write to one of the characteristic is something following.
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Operation failed with ATT error: 0x0e (Unlikely Error)
What I tried so far?

Some of the suggestions on the internet is regarding to downgrade the Bluez package which I have tried. One more suggestion is to increase the maximum writable package(mtu) size but I think this may not be an issue as I can write gatt values via nrfconnect.

There is also arduino library for nibble which I just tried weather it works and it works in writing characteristic values, hence my best guess is that there is some issue in my esp-idf code itself.

ujurmsde
Posts: 38
Joined: Tue Jan 19, 2021 6:37 am

Re: Error in writing the BLE characteristic data from Linux Bleak library to the nimble stack running on esp32.

Postby ujurmsde » Tue Nov 29, 2022 4:13 pm

In the meantime, I was looking for possibility of this error and think that there is/might be some bug in Nimble stack implementation or in my code writing style.

So I wrote similar code with arduino and realized that I must first define the write property and then read property of the characteristic in the code. Then it is able to write.!

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 124 guests