简体   繁体   中英

BlueNRG Bluetooth: read central device name

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.

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 -

在此处输入图片说明

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM