This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Identify Device Based on Advertising Data

I am connecting to two identical devices, but one is configured as device 'A' and the other is device 'B'. I am currently advertising whether the device is configured as A or B, and am able to connect to them selectively, but I'm not sure how to associate the device configuration with the handle or some other identifier that would be available in device_manager_event_handler().

For example, in on_ble_evt() when I get an BLE_GAP_EVT_ADV_REPORT event, I check to see what configuration the device is advertising. I would like to store this along with some other identifier so that when I get a DM_EVT_DISCONNECTION event in device_manager_event_handler() I can print out "Device B Disconnected"

So my question is what identifier can I use for this, or is there another way to accomplish what I'm trying to do?

EDIT: I tried using the address to correlate the advertising device with the connected device, but the last byte of the addresses do not match:

on_ble_evt() : 
p_ble_evt->evt.gap_evt.params.scan_req_report.peer_addr

device_manager_event_handler():
p_event->event_param.p_gap_param->params.scan_req_report.peer_addr.addr
  • Hey!

    I would create a data struct for each device with the following info:

    • Peer Adress
    • Peer Configuration (A or B)
    • Connection Handle

    When reading the advertisement report and deciding to connect, save the peer address along with the configuration. When the connection event happens. Find the correct device data struct, and fill inn the connection handle. When the disconnect (or other events) happen, use the connection handle to identify the device, and check the corresponding configuration.

    EDIT: If the addresses of the two devices are identical for some reason, you can add a custom read only characteristic to your service which describes the configuration.

    EDIT2, finding the addresses: This is where you should find the address in the two events:

            case BLE_GAP_EVT_CONNECTED:
    			adress = p_ble_evt->evt.gap_evt.params.connected.peer_addr;
    			break;
    		case BLE_GAP_EVT_ADV_REPORT:
    			adress = p_ble_evt->evt.gap_evt.params.adv_report.peer_addr;
    			break
    
  • Where should I be identifying the peer address? I tried doing what I describe in my edit above, but like I say, the addresses do not match in the last byte.

  • Thanks, I was checking the address in the device_manager_event_handler() for the connection event, but I'm looking under on_ble_evt() now.

  • I just realized that I need to also identify which device was bonded with under device_manager_event_handler(). Can you let me know what parameter I can correlate here? Currently I'm storing p_ble_evt->evt.gap_evt.conn_handle on connection but it doesn't match the p_event->event_param.p_gap_param->conn_handle I have at bonding.

Related