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

[TW#13066] BLE Write Characteristic esp_ble_gattc_write_char() not working #663

Closed source-creator closed 7 years ago

source-creator commented 7 years ago

When I call this function, I get:

E (33016) BT: BTA got unregistered event id 31

What is the correct usage of this function? How can I write to a characteristic? When can I write? Please provide an example.

FHFS commented 7 years ago

try gattc_demo.c:174 or :271, there I do see esp_ble_gattc_write_char_descr getting called

It looks like the bta_sys_cb for id 31(BTA_ID_GATTC) is not set. esp-idf/components/bt/bluedroid/bta/sys/bta_sys_main.c:502 esp-idf/components/bt/bluedroid/bta/include/bta_sys.h:91

Any context on your code and what you are trying to accomplish?

source-creator commented 7 years ago

What does that mean? How can I set that callback?

I looked at gattc_demo.c - I had previously looked at it before, but that function is for setting the descriptor.

Basically I want to make something that can write a value every so often, eg Temperature.

Weijian-Espressif commented 7 years ago

@timothycoutlakis , what do you mean? Do you want write to a characteristic in gatt client ? or in gatt server ?

in the gatt client , I write 30 bytes to gatt server ,

case ESP_GATTC_GET_CHAR_EVT:
    if (p_data->get_char.status != ESP_GATT_OK) {
        break;
    }
    ESP_LOGI(GATTC_TAG, "GET CHAR: conn_id = %x, status %d", p_data->get_char.conn_id, p_data->get_char.status);
    ESP_LOGI(GATTC_TAG, "GET CHAR: srvc_id = %04x, char_id = %04x", p_data->get_char.srvc_id.id.uuid.uuid.uuid16, p_data->get_char.char_id.uuid.uuid.uuid16);

    if (p_data->get_char.char_id.uuid.uuid.uuid16 == 0xee01) {
        gl_profile_tab[PROFILE_A_APP_ID].char_id = p_data->get_char.char_id;

        uint8_t value[30];
        for (int i = 0; i < sizeof(value); ++i)
        {
            value[i] = i;
        }
        esp_ble_gattc_write_char(gattc_if,
                                conn_id,
                                &alert_service_id,
                                &gl_profile_tab[PROFILE_A_APP_ID].char_id,
                                sizeof(value),
                                value,
                                ESP_GATT_WRITE_TYPE_RSP,
                                ESP_GATT_AUTH_REQ_NONE);

    }

    esp_ble_gattc_get_characteristic(gattc_if, conn_id, &alert_service_id, &p_data->get_char.char_id);
    break;
source-creator commented 7 years ago

@Weijian-Espressif Thank you for your reply.

I have an Android BLE client app which connects to the Gatt server on ESP32. I would like to write to a characteristic from the ESP32 Gatt server, so that the Android client can receive it.

Weijian-Espressif commented 7 years ago

hi @timothycoutlakis In our gatt_server demo, you can use esp_ble_gatts_send_indicate(esp_gatt_if_t gatts_if, uint16_t conn_id, uint16_t attr_handle, uint16_t value_len, uint8_t *value, bool need_confirm). This function is used to send indicate or notify to GATT client.

source-creator commented 7 years ago

@Weijian-Espressif Thank you for your reply, I will take a look.

FayeY commented 7 years ago

Hi @timothycoutlakis , is this problem solved? Can we close this issue?