BLE GATT server doesn't read/write value

phatpaul
Posts: 109
Joined: Fri Aug 24, 2018 1:14 pm

BLE GATT server doesn't read/write value

Postby phatpaul » Wed Feb 20, 2019 3:03 pm

I need some clarification on the intended behavior of the GATT server.

I have some characteristics defined using ESP_GATT_AUTO_RSP, and I supplied a pointer to the value when creating the gatt table.

The value is stored in a global uint8_t array.
static uint8_t char_value[20] = {0x02}; // global array to store char value

const esp_gatts_attr_db_t serv_gatt_db[SERV_NUM_ATTR] =
{
...
[CMD_VAL] = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *) &POCO_COMMAND_uuid, ESP_GATT_PERM_WRITE, sizeof(char_value), sizeof(char_value), (uint8_t *)char_value}},
...

I can read and write them via BLE, but it seems my global array is never changed.

When I first read the characteristic, it returns what I have initialized the global to. I read [02 00 00 00 00 ...], just as expected.
Then I write the value via BLE to 0x1234.
I can then read via BLE and it returns [12 34] as expected.
But my global array has not been changed.
Also, if I change my global array value via other means (not via BLE), the value I read via BLE is not changed.

So it seems there is some internal buffer in the BLE stack storing the value. It seems the global array that I passed to the stack on creation is only used to initialize the internal value.

Questions:
* How and when do I access the internal value?

* If the BLE stack is supposed to write to my global array automatically, does it do so before or after triggering ESP_GATTS_WRITE_EVT (or ESP_GATTS_EXEC_WRITE_EVT)?

* If the BLE stack is supposed to read from my global array automatically, does it do so before or after triggering ESP_GATTS_READ_EVT?

* Where is the intended behavior documented?

Note: I realize that I could use ESP_GATT_RSP_BY_APP and write code to handle the read/write to my global array. But I am using long-write and long-read, because the size of array may be larger than MTU. i.e. static uint8_t char_value[128] I want to use ESP_GATT_AUTO_RSP because it seems that the BLE stack is (somehow) taking care of the chunking required for long-write and long-read automatically.

FYI: Here's a relevant post that I almost resurrected: https://www.esp32.com/viewtopic.php?f=1 ... T_AUTO_RSP

phatpaul
Posts: 109
Joined: Fri Aug 24, 2018 1:14 pm

Re: BLE GATT server doesn't read/write value

Postby phatpaul » Tue Feb 26, 2019 3:34 pm

FYI Since no response for a week I opened an issue https://github.com/espressif/esp-idf/issues/3102

Who is online

Users browsing this forum: No registered users and 104 guests