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

Directed Advertising - How to make it work?!

Hi

Struggling getting Directed Advertising to work - I have been through all the examples and have been using the ble_app_hids_keyboard_nfc_pairing example.

My NRF52832 application generates a unique MAC in Main at startup. The device is a peripheral, and it should only allow the connection of ONE specific central per 'session' ('session' starts at main and end when power turned off).

I was hoping to do this simply without using the whitelist module which appears to be overkill for my needs. What I need is pretty simple, if no bonded centrals, do fast advertising forever, once central bonds, store its MAC and if it disconnects, do directed advertising forever. Client device is Android, and I am back to using nRFConnect as my 'app' until I can get this working. My steps are:

1) When my peripheral starts, it advertises via Fast Advertising forever with no timeout 

2) The central connects and bonds (using nrfconnect), on a successful bond, the peer_id gets put into static pm_peer_id_t  m_peer_id; as per the hids_keyboard example above

3) On nrfConnect, I disconnect, In the 52832 code, I respond to the callback 'BLE_ADV_EVT_PEER_ADDR_REQUEST' with err_code = ble_advertising_peer_addr_reply(&m_advertising, p_peer_addr);

4) handler on_adv_evt correctly receives BLE_ADV_EVT_DIRECTED

5) on nRFConnect scanner tab, I should see the same peripheral MAC address doing Directed Advertising eg directed at me --> I CANNOT

6) On nRFConnect I should be able to goto paired devices and tap 'Connect', and have the pre-existing connection/bond re-established --> I CANNOT

Does anyone have any idea's?

//my config -- APP_DIRECTED_ADV_INTERVAL is 300 and I want directed advertising forever for reconnects hence the '0'

		init.config.ble_adv_directed_high_duty_enabled = true;
		init.config.ble_adv_directed_enabled = true;
		init.config.ble_adv_directed_interval = APP_DIRECTED_ADV_INTERVAL;
		init.config.ble_adv_directed_timeout = 0;
    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
		
		init.config.ble_adv_whitelist_enabled = false;
		init.config.ble_adv_on_disconnect_disabled = false;

pm_evt_handler

case PM_EVT_CONN_SEC_SUCCEEDED:
        {
            NRF_LOG_INFO("Connection secured: role: %d, conn_handle: 0x%x, procedure: %d.",
                         ble_conn_state_role(p_evt->conn_handle),
                         p_evt->conn_handle,
                         p_evt->params.conn_sec_succeeded.procedure);
					
						m_peer_id = p_evt->peer_id;
        } break;
        

on_adv_evt

case BLE_ADV_EVT_PEER_ADDR_REQUEST:
				
				NRF_LOG_INFO("Peer Request.");

				pm_peer_data_bonding_t peer_bonding_data;
			
				if (m_peer_id != PM_PEER_ID_INVALID)
        {
						err_code = pm_peer_data_bonding_load(m_peer_id, &peer_bonding_data);
						if (err_code != NRF_ERROR_NOT_FOUND)
						{
								APP_ERROR_CHECK(err_code);
								ble_gap_addr_t * p_peer_addr = &(peer_bonding_data.peer_ble_id.id_addr_info);
								err_code = ble_advertising_peer_addr_reply(&m_advertising, p_peer_addr);
                APP_ERROR_CHECK(err_code);
            }
        }
			
			
				break;

Parents Reply Children
Related