Firstly I'm extremely new to BLE in general so i may be using the wrong terminology, please mention if i do so i can learn.
I'm using the BTStack library on an ESP32 to communicate with a web app ive written and got some odd behaviour.
When requesting a value from a connected characteristic the att_read_callback handler to service the request runs twice, but the web app only receives a single response.
Iv'e tested running the att_delayed_response example from BTStack here
Iv'e tried my own simple variation of this which can be viewed Here
Iv'e tried connecting with my webapp and a simple BLE app on my smart both and both times the read callback is executed twice.
I'm at a loss why this is happening. It doesn't cause any stability issues but im trying to build a foundation to build more complex apps upon so this seems like a fundamental issue i need to understand.
On the ESP side i create the server just as in the docs using the generate profile data from the .gatt file
att_server_init(profile_data, att_read_callback, att_write_callback);
and my read callback looks like this
static uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
UNUSED(connection_handle);
printf("\n\nIm Hit\n\n");
// This is our auto generated attribute UUID handle. This is how we check the read came from characteristic A vs B
if (att_handle == ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE){
// Get the value to send to the connected device by executing our onRead callback
const char * response = onReadCallback();
return att_read_callback_handle_blob((const uint8_t *)response, (uint16_t) strlen(response), offset, buffer, buffer_size);
}
return 0;
}
Im Hit gets logged twice per read request.
There is so much configuration going on with advertisement data and GAPconfiguration it difficult for me to pin down the exact relevant code.