Write Data in Other Characteric BLE

pierrel
Posts: 2
Joined: Wed Aug 29, 2018 3:56 pm

Write Data in Other Characteric BLE

Postby pierrel » Thu Aug 30, 2018 7:30 pm

Hi everybody,

I'm using the "gatt_server" example (https://github.com/espressif/esp-idf/bl ... tts_demo.c)
and I have some troubles to write and indicate datas in a different characteric that the one I handle.

For example I have 2 services A and B, when I receive a WRITE_EVT in service A, I want to write other datas in a characteristic in the service B.

This is the code part that handle the WRITE_EVT on the service A :

Code: Select all

case ESP_GATTS_WRITE_EVT: {
        ESP_LOGI(GATTS_TAG, "GATT_WRITE_EVT, conn_id %d, trans_id %d, handle %d", param->write.conn_id, param->write.trans_id, param->write.handle);
        if (!param->write.is_prep){
            ESP_LOGI(GATTS_TAG, "GATT_WRITE_EVT, value len %d, value :", param->write.len);
            esp_log_buffer_hex(GATTS_TAG, param->write.value, param->write.len);
			
            if (gl_profile_tab[PROFILE_A_APP_ID].descr_handle == param->write.handle && param->write.len == 2){
                uint16_t descr_value = param->write.value[1]<<8 | param->write.value[0];
                if (descr_value == 0x0001){
                    if (a_property & ESP_GATT_CHAR_PROP_BIT_NOTIFY){
                        ESP_LOGI(GATTS_TAG, "notify enable");
                        uint8_t notify_data[15];
                        for (int i = 0; i < sizeof(notify_data); ++i)
                        {
                            notify_data[i] = i%0xff;
                        }
                        //the size of notify_data[] need less than MTU size
                        esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, gl_profile_tab[PROFILE_A_APP_ID].char_handle,
                                                sizeof(notify_data), notify_data, false);
                    }
                }else if (descr_value == 0x0002){
                    if (a_property & ESP_GATT_CHAR_PROP_BIT_INDICATE){
                        ESP_LOGI(GATTS_TAG, "indicate enable");
                        uint8_t indicate_data[15];
                        for (int i = 0; i < sizeof(indicate_data); ++i)
                        {
                            indicate_data[i] = i%0xff;
                        }
                        //the size of indicate_data[] need less than MTU size
                        esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, gl_profile_tab[PROFILE_A_APP_ID].char_handle,
                                                sizeof(indicate_data), indicate_data, true);
                    }
                }
                else if (descr_value == 0x0000){
                    ESP_LOGI(GATTS_TAG, "notify/indicate disable ");
                }else{
                    ESP_LOGE(GATTS_TAG, "unknown descr value");
                    esp_log_buffer_hex(GATTS_TAG, param->write.value, param->write.len);
                }

            }
        }		
		example_write_event_env(gatts_if, &a_prepare_write_env, param);
		
		esp_ble_gatts_send_indicate(gl_profile_tab[PROFILE_B_APP_ID].gatts_if, 0, gl_profile_tab[PROFILE_B_APP_ID].char_handle, "Test", 4, false);
        break;
I tried to use this funtion (and tons of others options) :

Code: Select all

esp_ble_gatts_send_indicate(gl_profile_tab[PROFILE_B_APP_ID].gatts_if, 0, gl_profile_tab[PROFILE_B_APP_ID].char_handle, "Test", 4, false);
But it returned me a guru meditation error :

Guru Meditation Error: Core 0 panic'ed (LoadProhibited)
. Exception was unhandled.
Core 0 register dump:
PC : 0x4000c2e0 PS : 0x00060a30 A0 : 0x800f1edd A1 : 0x3ffb3110
A2 : 0x3ffe4920 A3 : 0x00000004 A4 : 0x00004890 A5 : 0x3ffe4920
A6 : 0x00000001 A7 : 0x00000489 A8 : 0x00000000 A9 : 0x3ffb30e0
A10 : 0x3ffe4920 A11 : 0x00004890 A12 : 0x3ffd56f3 A13 : 0x00000000
A14 : 0x00000001 A15 : 0x00000000 SAR : 0x00000008 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000004 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00000488

Backtrace: 0x4000c2e0:0x3ffb3110 0x400f1eda:0x3ffb3120 0x400ed0de:0x3ffb3150 0x400eaab5:0x3ffb3180 0x400d57ef:0x3ffb31d0 0x400d5119:0x3ffb3470 0x400f2346:0x3ffb34a0 0x400ed08e:0x3ffb34e0
0x400f1eda: btc_gatts_arg_deep_copy at /root/esp/esp-idf/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c:482

0x400ed0de: btc_transfer_context at /root/esp/esp-idf/components/bt/bluedroid/btc/core/btc_task.c:155

0x400eaab5: esp_ble_gatts_send_indicate at /root/esp/esp-idf/components/bt/bluedroid/api/esp_gatts_api.c:277

0x400d57ef: gatts_profile_a_event_handler at /root/esp/BRIO_RC_ESP32/main/ble.c:573

0x400d5119: gatts_event_handler at /root/esp/BRIO_RC_ESP32/main/ble.c:1020

0x400f2346: btc_gatts_cb_to_app at /root/esp/esp-idf/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c:54
(inlined by) btc_gatts_cb_handler at /root/esp/esp-idf/components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c:774

0x400ed08e: btc_task at /root/esp/esp-idf/components/bt/bluedroid/btc/core/btc_task.c:110



Some help would be welcome !
Thanks in advance.

chegewara
Posts: 2240
Joined: Wed Jun 14, 2017 9:00 pm

Re: Write Data in Other Characteric BLE

Postby chegewara » Fri Aug 31, 2018 11:41 pm

Check your parameters order:
https://docs.espressif.com/projects/esp ... P7uint8_tb

Also you cant pass literal string as a parameter for value type of uint8_t*.

pierrel
Posts: 2
Joined: Wed Aug 29, 2018 3:56 pm

Re: Write Data in Other Characteric BLE

Postby pierrel » Wed Oct 03, 2018 4:27 pm

Thanks for your response.

My first try was with this line :

Code: Select all

esp_ble_gatts_send_indicate(gl_profile_tab[PROFILE_B_APP_ID].gatts_if, gl_profile_tab[PROFILE_B_APP_ID].conn_id, gl_profile_tab[PROFILE_B_APP_ID].char_handle, dataValueStr, sizeof(dataValueStr), false);
I have the same Guru meditation error, but I think it's because I didn't get conn_id in the CONNECT_EVT :

Code: Select all

case ESP_GATTS_CONNECT_EVT:
        ESP_LOGI(GATTS_TAG, "CONNECT_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:",
                 param->connect.conn_id,
                 param->connect.remote_bda[0], param->connect.remote_bda[1], param->connect.remote_bda[2],
                 param->connect.remote_bda[3], param->connect.remote_bda[4], param->connect.remote_bda[5]);
        gl_profile_tab[PROFILE_B_APP_ID].conn_id = param->connect.conn_id;
        break;
I have this line in the log :

I (788526) GATTS_DEMO: CONNECT_EVT,conn_id 0, remote 7f:ce:2f:be:70:ed:

I tried also to set gl_profile_tab[PROFILE_B_APP_ID].conn_id with a hard value but I got a new error :

E (65016) BT_LOG: esp_ble_gatts_send_indicate, the l2cap chanel is congest.

Any ideas ?

chegewara
Posts: 2240
Joined: Wed Jun 14, 2017 9:00 pm

Re: Write Data in Other Characteric BLE

Postby chegewara » Wed Oct 03, 2018 5:13 pm

Its congestion, try to add small delay(3-5ms) right before send indicate.

Who is online

Users browsing this forum: Google [Bot], JP5654, tomy983 and 227 guests