How to get peer BLE address after connected?

We can get BLE address in adv report: How to get mac address of nearby ble devices? - Nordic Q&A - Nordic DevZone - Nordic DevZone

At that moment, peripheral not connected yet,I can't build address-conn_hande relationship.

We can get the peer address through API call?

Of cause,we can get it through defining characteristic or some self-defined protocol.

Parents
  • Based on your other recent questions, I guess you are using the nRF5 SDK, and I will reply as if you are still using it. If this is wrong, and you are using NCS, please let me know.

    We can get the peer address through API call?

    No, it is no part of the BLE events that contain the BLE address, other than in the connected event itself. In the connected event, you can see the peer address, and you will see the conn_handle. The conn_handle will remain the same until the device disconnects, so you can use this conn_handle to keep track of which device you are connected to. If you need to keep track of what BLE address the conn handle belongs to, I suggest you create an array consisting of conn_handles, and one array of BLE addresses. Then, upon connection, you check for the first element in the conn_handle array that is not empty (initialize them all to BLE_CONN_HANDLE_INVALID, and set them in the connected event). Then you know this element, the N'th element will be for this connection. Then you can populate the N'th element of the BLE address array to the address from the connected event. 

    When you are disconnected, remember to set the conn handle in the conn_handle array to BLE_CONN_HANDLE_INVALID again, to keep track of what connections that are active or not.

    Best regards,

    Edvin

  • Get it.

    Thank you.

    I have added a characteristic to the service to provide BLE address.Read the characteristic after connected.

Reply Children
No Data
Related