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;

  • Hi

    Still no joy, I changed the  adv_directed_timeout from zero to 10000. App now runs through the available advertising methods. Still cannot re-connect while Directed advertising is being done, can connect after it switches to FAST, but that does not fit my requirements. I can only assume that nothing is being advertised during the 'directed' period- maybe there is another setting in the SDK that I need to enable?

    I have checked that the MAC that gets stored away at initial bond time matches that of the device in question, and also that the same MAC is retrieved via ble_advertising_peer_addr_reply prior to directed advertising being started. Now at a total loss re how to make this work.

    Edit: Just setup the sniffer - someone needs to look at the instructions for that, they are awful! Oh, and make it work with the 'nRF82840-Dongle' too (currently there is no way to get the firmware onto it).

    Anyway, I am getting direct advertisment packets, despite  nRFConnect (running on Android) complete refusal to re-connect to the peripheral using them.

    10070 225.442 f6:d7:12:6c:99:d8 LE 1M LE LL 12 500 0 ADV_DIRECT_IND

    10071 225.449 f6:d7:12:6c:99:d8 LE 1M LE LL 12 500 0 ADV_DIRECT_IND

    Adv data thus, and the MAC of the central is in there 9C:E0:63:FC:FC:D6

    0000 06 1f 00 02 86 35 06 0a 01 25 31 00 00 4f d7 02
    0010 00 d6 be 89 8e 21 0c d8 99 6c 12 d7 f6 d6 fc fc
    0020 63 e0 9c b6 ca e5

    Wireshark screenshot below. Given that this does not even re-connect with nRFConnect (android), it looks like I shall have to give up! No hope of me getting it to work with my own app.

    Nigel

  • Hi,

    It may be that the specific android phone you have don't support directed advertising. To ensure that directed advertising is supported the peripheral device should do a discovery of the central address resolution characteristic (CAR) of the phone, and if it is bonded and supported by the phone, then the peripheral can do directed advertisement. The implementation to check for CAR was included for the HID examples in SDKv15.2, you may try: \nRF5_SDK_15.2.0_9412b96\examples\ble_peripheral\ble_app_hids_keyboard for comparison.

    Best regards,
    Kenneth

  • Oh.... As directed advertising appears to be a standard part of BLE 4.2 and all devices I am targeting are BLE 4.2 or better I assumed this would just work.

    Guess I will have to forget directed advertising as a solution and return to fast advertising+whitelisting.

    Unfortunately, the BLE is a tiny component in our project, but by far the most frustrating and time consuming component!

    Nigel

  • For instance directed is not supported by iOS:
    https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf (chapter 10.3) 

    You might also find other relevant information there.

  • Cheers, I have disabled all directed advertising and am now using the whitelist method from the hid_keyboard example...

Related