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

Directed advertising with Peer Manager, single central

I have a peripheral device based on the nRF51822, s130 and SDK 11.0.0. It's designed to only ever have one central device to which it's bonded. Out of the box, without a bond yet, it does undirected advertising until it gets its first connection and bonds. After that, it only ever does directed advertising.

How do I respond to the BLE_ADV_EVT_PEER_ADDR_REQUEST advertising event in this case?

I want to ask the Peer Manager for the address of the bonded central, then pass that to ble_advertising_peer_addr_reply(). But the call to pm_peer_data_bonding_load() takes a peer ID, which I don't have. After the first connection and bonding, I'll have gone into sys off or reset before the subsequent connections.

Parents
  • Stealing from the HID keyboard example just iterate the ids out of the peer manager

    pm_peer_id_t peer_id = pm_next_peer_id_get(PM_PEER_ID_INVALID);
    

    gets you the first peer id. Since you only have one, that's the one you want. If that returns PM_PEER_ID_INVALID then you don't have one and that tells you you have no bond yet and should advertise undirected until you get that one bond set up.

    That method of iterating the known peers is in the documentation, has an example there too.

Reply
  • Stealing from the HID keyboard example just iterate the ids out of the peer manager

    pm_peer_id_t peer_id = pm_next_peer_id_get(PM_PEER_ID_INVALID);
    

    gets you the first peer id. Since you only have one, that's the one you want. If that returns PM_PEER_ID_INVALID then you don't have one and that tells you you have no bond yet and should advertise undirected until you get that one bond set up.

    That method of iterating the known peers is in the documentation, has an example there too.

Children
Related