I need to switch between 3 central devices (device slots, rather) with a peer manager and SDK 12.3.0 (nrf51822-based keyboard, see sdk12_3 branch for a peer manager https://github.com/joric/mitosis/tree/devel). Can anyone tell me how to do that properly or maybe there's an example?
I guess there are difference ways of doing this, but the simplest may be to just control the GAP address for the peripheral device before starting to advertise:
err_code = sd_ble_gap_addr_get(&gap_addr);
gap_addr.addr = 1; // switch status 1, 2, or 3
err_code = sd_ble_gap_addr_set(&gap_addr);
That way the peripheral device will appear as a new peripheral device depending on the current GAP address, and only the specific central that have bonded with the current GAP address will connect to it.
The next problem you will face is to know which old bond you should delete if you pair with a new central. This may be solved by storing the state of the switch (or GAP address) after successful bonding by calling something like:
uint16_t length = 8;
for(uint8_t i=0; i<BLE_GAP_ADDR_LEN; i++)
addr[i] = gap_addr.addr[i];
err_code = pm_peer_data_app_data_store(m_peer_id,addr,length,NULL);
To retrieve saved states of the switch (or GAP address) later you can call pm_peer_data_bonding_load() followed by pm_peer_delete() to delete a specific bond. You should look at the implementation of peer_list_get() on how to cycle through bonds (bonded peer id's). E.g.:
static void peer_list_find_and_delete_bonds(void)
peer_id = pm_next_peer_id_get(PM_PEER_ID_INVALID);
while (peer_id != PM_PEER_ID_INVALID)
// Call pm_peer_data_app_data_load()
// Check stored switch (or GAP address)
// if previously bonded you can call pm_peer_delete()
peer_id = pm_next_peer_id_get(peer_id);
I didn't quite get the thing the the address. I can change the address, but how do I advertise to a second peer when I already have one bonded peer? Should I advertise with an empty whitelist or something?
OK I think ble_advertising_restart_without_whitelist() worked. I'll test it and maybe post full solution then.
That is the correct api you can use to bond with a new central yes.