i'm working on "gatt_server" example using ESP32 as BLE server and Android app "BLEscanner" as BLE client. I have been able to make the basic code work so i can discovery and connect. I'm making experiments to improve my ESP-IDF knowledge (i'm using the esp-idf 2.0 RC) adding some features to the example but i'm having hard time with notifications. Let me explain with code:
I started declaring a variable:
Code: Select all
uint8_t experiment = 0xEE;
Code: Select all
case ESP_GATTS_READ_EVT: {
esp_gatt_rsp_t rsp;
memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
rsp.attr_value.handle = param->read.handle;
rsp.attr_value.len = 1;
rsp.attr_value.value[0] = experiment;
esp_ble_gatts_send_response(gatts_if, param->read.conn_id,
param->read.trans_id, ESP_GATT_OK, &rsp);
break;
About the write operation i tried write this code:
Code: Select all
case ESP_GATTS_WRITE_EVT: {
if (param->write.handle== gl_profile_tab[0].char_handle) { //[0] because i'm using profile A
experiment = (uint8_t)*param->write.value;
} else if (param->write.handle== gl_profile_tab[0].descr_handle) {
esp_ble_gatts_set_attr_value(gl_profile_tab[0].descr_handle, param->write.len,(uint8_t*) param->write.value);
experiment=0xBB;
}
esp_ble_gatts_send_response(gatts_if, param->write.conn_id,param->write.trans_id, ESP_GATT_OK, NULL);
break;
What i'm doing wrong? Any suggestion would be appreciated!
Regards,
Frax