3

I'm using the STM BlueNRG-MS chip on my peripheral device and after connection I'd like to read the name of the connected central device (android phone).

I thought I can do this directly in my user_notify routine which is registered as hci callback

  /* Initialize the Host-Controller Interface */
  hci_init(user_notify, NULL);

So on the EVT_LE_CONN_COMPLETE event, I take the provided handle for the central device and I use aci_gatt_read_using_charac_uuid() to read what I thought is the characteristic with the device name (uuid 0x2a00).

case EVT_LE_META_EVENT:
    {
      evt_le_meta_event *evt = (void *)event_pckt->data;
      switch(evt->subevent){
      case EVT_LE_CONN_COMPLETE:
        {
          evt_le_connection_complete *cc = (void *)evt->data;
                    GAP_ConnectionComplete_CB(cc->peer_bdaddr, cc->handle);
                    uint16_t uuid = 0x2a00;
                    resp = aci_gatt_read_using_charac_uuid(cc->handle, 0, 1, UUID_TYPE_16, (uint8_t*)&uuid);
                    LOG("GATT read status: %d", resp);

          enqueEvent(EVENT_BLE_CONNECTED);
        }
        break;
      }
    }

Long story short, it doesn't work. First thing I'm not sure about is, what is the start_handle and end_handle parameter of aci_gatt_read_using_charac_uuid(), it returns ERR_INVALID_HCI_CMD_PARAMS.

Can someone shed some light here?

update
What also puzzles me is that the function aci_gatt_read_using_charac_uuid() is nowehere referenced in the BlueNRG-MS Programming Guidelines.

update2
I changed the function call to aci_gatt_read_using_charac_uuid(cc->handle, 0x0001, 0xffff, UUID_TYPE_16, (uint8_t*)&uuid); but I still get the ERR_INVALID_HCI_CMD_PARAMS. What which paramter could even be invalid? The uuid exists, I can read the device name if I use the BlueNRG GUI with a bluetooth dongle.

update3
Has anyone ever used this function or somehow managed to read a characteristic from a central device? I'd highly appreciate any help or hint.

po.pe
  • 1,047
  • 1
  • 12
  • 27

2 Answers2

1

Here you go, The BlueNRG-MS Bluetooth® LE stack application command interface (ACI) - User manual

page 75 - 4.6.25 Aci_Gatt_Read_Charac_Using_UUID() and make sure you have called Aci_Gatt_Init()

The user manual is last revised July 2019, the document you link to is from 2018, don't know if this is why ?

The start_handle and end_handle is the range of handles in your service as pictured here -

enter image description here

Here is a discussion to the closest thing I could find to match your question.

Sorenp
  • 320
  • 2
  • 12
  • Thanks... I understand that I have handles for my local services and characteristics, that works like a charm, but what are the handles for a remote characteristic? – po.pe Jul 14 '21 at 10:00
  • I know you can switch mode from peripheral to central and vice versa, that way you request the 0x180A, (Device Information Service) from the android phone. – Sorenp Jul 14 '21 at 10:36
  • So I first have to request the service before I can access one of its characteristics? – po.pe Jul 14 '21 at 11:27
  • Officially yes, you have to discover the services first, then choose switch characteristic you want to access, now you can "avoid" this by being bonded to the device which will make service discovery time "zero" on subsequent connections, as the first discovery is cached, I know phones do this, but I don't know how to do it ;) – Sorenp Jul 14 '21 at 11:35
  • Still couldn't get it to work, I used `0x0001` as `start_handle` and `0xffff` as `end_handle`, but I still get the response `ERR_INVALID_HCI_CMD_PARAMS`. The same approach seems to work when I do it from the BlueNRG GUI – po.pe Jul 15 '21 at 07:18
  • According to the description of `Aci_Gatt_Read_Charac_Using_UUID()` the return value `18` for `ERR_INVALID_HCI_CMD_PARAMS` shouldn't even be possible... – po.pe Oct 25 '21 at 07:36
0

As it turned out there are two bugs in the BlueNRG API.

In bluenrg_aci_const.h file the OCF code OCF_GATT_READ_USING_CHARAC_UUID shall be 0x119 instead of 0x109. And in the implementation of the aci_gatt_read_using_charac_uuid() function, there is a missing setting on event:

rq.event = EVT_CMD_STATUS;

Patching them fixed the issue.

po.pe
  • 1,047
  • 1
  • 12
  • 27