sd_ble_gattc_characteristics_discover returns extra characteristics

I'm using SDK 17.0.2 and I'm trying to write a small central device. It should connect to a single peripheral and exchange some data.

Once the peripheral is found, central connects and discovers services.

I then triggers characteristics discovery:

          NRF_LOG_INFO("Discovering characteristics %.4X-%.4X.....", handleRange.start_handle, handleRange.end_handle);
          err_code = sd_ble_gattc_characteristics_discover(p_ble_evt->evt.gap_evt.conn_handle, &handleRange);

This outputs: "Discovering characteristics 0011-FFFF....." (I don't necessarily understand this handle range, if anyone can point to a document that explains how handles are generated, I'd be interested, otherwise, I consider them as opaque data)

Here's the code that handles the characteristics discovery:

        if (p_ble_evt->evt.gattc_evt.gatt_status == BLE_GATT_STATUS_SUCCESS)
        {
          ble_gattc_evt_char_disc_rsp_t char_disc = p_ble_evt->evt.gattc_evt.params.char_disc_rsp;

          NRF_LOG_INFO("Got %d chars.......", char_disc.count);
          for (int i = 0; i < char_disc.count; ++i)
          {
            handleRange.start_handle = char_disc.chars[i].handle_value + 1;
            NRF_LOG_INFO("%d: %.4X (%.2X)/%.4X/%.4X chars.......", i, char_disc.chars[i].uuid.uuid, char_disc.chars[i].uuid.type, char_disc.chars[i].handle_decl, char_disc.chars[i].handle_value);
          }
        }

Here's the output I get:

Got 3 chars.......
0: A001 (01)/0012/0013 chars.......
1: 4D94 (00)/0000/E000 chars.......
2: E000 (10)/0000/0000 chars.......

The first characteristic is correct. It exists, I can see it when connecting to the peripheral using nRFConnect.

The 2 others don't, one has a UUID type that's not defined, plus both have declaration handle 0. What is this? What does that mean?

I wrote code that discards them and keeps enumerating, and I manage to get all the characteristics that I can see in nRFConnect. But I'm very curious as to what that is... Looking at ble_app_interactive sample, in ble_m.c, "on_characteristics_discovery_rsp", I can't find any code that would discard any characteristics, so I suppose I'm doing something wrong...

  • Hello,

    Here's the code that handles the characteristics discovery:

    Where is this snippet called from? 

    It doesn't look very much like the method used in the central examples from the SDK. I see that sd_ble_gattc_characteristics_discover() is being used, but not directly (only through the discovery module). 

    From the on_characteristic_discovery_rsp() in ble_db_discovery.c I see that it checks the conn_handle. Do you check that as well?

    Best regards,

    Edvin

Related