espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.51k stars 7.26k forks source link

Issues with esp_ble_gatts_send_indicate - Gatts Server Service Table Demo and BLE interrogator (IDFGH-2304) #4442

Closed jonhunterking66 closed 4 years ago

jonhunterking66 commented 4 years ago

Environment

Problem Description

When using a BLE interrogator I cannot receive notifications when using the esp_ble_gatts_send_indicate function

Expected Behavior

I expect that when I enable notifcations on the BLE scanner app after connection the value will updated as I call esp_ble_gatts_send_indicate

Actual Behavior

There is no change in value, all I receive is the string built in from the gatts server service table demo [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]

Steps to repropduce

  1. Open the Gatts Server Service table demo
  2. Use the BLE scanner app
  3. Add the following code to the end of the main function:

    uint8_t data[20] = {0x66, 0x66};
    while (true){
        ets_delay_us(100000);
    
        ret = esp_ble_gatts_send_indicate(heart_rate_profile_tab[IDX_CHAR_VAL_A].gatts_if, heart_rate_profile_tab[IDX_CHAR_VAL_A].conn_id, heart_rate_handle_table[IDX_CHAR_VAL_A], sizeof(data),data, false);
        if (ret){
            ESP_LOGE(GATTS_TABLE_TAG, "Send indication, error code = %x", ret);
            return;
        }
    
        data[0] = data[0] + 1;
    
    }
  4. Flash code to ESP 32
  5. Connect to device on BLE scanner app
  6. Enable notifications for custom service

Here is the link to the example: https://github.com/espressif/esp-idf/tree/master/examples/bluetooth/bluedroid/ble/gatt_server_service_table

The code I added is above.

Any help is appreciated.

gengyuchao commented 4 years ago

Hi, because the Bluetooth protocol stack runs in freeRTOS, you should use vTaskDelay instead of ets_delay_us, otherwise it will stop the work of BT Stack.