BLE characteristics UUID

kate11
Posts: 1
Joined: Mon Apr 10, 2017 11:43 am

BLE characteristics UUID

Postby kate11 » Mon Apr 10, 2017 11:50 am

How can I know the UUID of the characteristic when ESP_GATTS_READ_EVT occurs in GATTS SERVER operation?

Code: Select all

  case ESP_GATTS_READ_EVT:
            ESP_LOGI(DEBUG_TAG, "GATT_READ_EVT, conn_id %d, trans_id %d, handle %d\n", param->read.conn_id, param->read.trans_id, param->read.handle);
            
            esp_gatt_rsp_t rsp;

            memset(&rsp, 0, sizeof(esp_gatt_rsp_t));

            rsp.attr_value.len = 4;

            rsp.attr_value.value[0] = 0xde;
            rsp.attr_value.value[1] = 0xed;
            rsp.attr_value.value[2] = 0xbe;
            rsp.attr_value.value[3] = 0xef;

            esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id,
                    ESP_GATT_OK, &rsp);

            break;

plz..help..

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: BLE characteristics UUID

Postby kolban » Mon Apr 17, 2017 3:59 am

I reserve the right to be completely wrong here:

My working assumption goes along the following lines.

A GATT server exposes characteristics.
What a GATT server starts, it maps those characteristics to local short integers called "handles". The "handles" are not hard-coded but are instead dynamically assigned when the GATT server starts and the characteristics are registered.
When a GATT client wants to read the value of a characteristic, it supplied the current "handle" as the value to read.
A GATT client can ask the GATT server for the current handles for each of the characteristics.

As an analogy, imagine a "drop in" office for mobile workers. I arrive at the office and ask the receptionist for a "desk". She says "You can have desk #4".

Now imagine someone wants to meet me ... they call my cell phone and I say "hello". They say "where are you?". I say "desk #4". They arrive at the office/floor and go to desk #4. In this story, the characteristic is "my name" and the handle is "my current desk".

In your GATT server code, when you register a characteristic, a GATT server event is fired called "ESP_GATTS_ADD_CHAR_EVT" and in the parameters for that callback, you are told the characteristic UUID that is the global identity of the characteristic and you are also passed in the attribute handle which is the handle used by a caller to read that characteristic on this server at this time.

Again ... this could be all wrong ... but lets advance it out there and see if we have a better description (or a confirmation).
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: No registered users and 136 guests