<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>best way to retrieve latest used BLE bonding infos using SDK16 peer manager library</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67516/best-way-to-retrieve-latest-used-ble-bonding-infos-using-sdk16-peer-manager-library</link><description>To the kind attention of Nordic support team, 
 I was reading in peer_manager library that when a ble connection is established, using the connection handler as a parameter should be possible to retrieve the index in the peer database where those connections</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 30 Oct 2020 11:33:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67516/best-way-to-retrieve-latest-used-ble-bonding-infos-using-sdk16-peer-manager-library" /><item><title>RE: best way to retrieve latest used BLE bonding infos using SDK16 peer manager library</title><link>https://devzone.nordicsemi.com/thread/277785?ContentTypeID=1</link><pubDate>Fri, 30 Oct 2020 11:33:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:daf4ee81-0fe3-4eef-9d68-e681919d4282</guid><dc:creator>astella</dc:creator><description>&lt;p&gt;But this is the very best solution:&amp;nbsp;&lt;/p&gt;
&lt;div&gt;pm_peer_ranks_get(&amp;amp;m_peer_id, NULL, NULL, NULL);&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: best way to retrieve latest used BLE bonding infos using SDK16 peer manager library</title><link>https://devzone.nordicsemi.com/thread/276705?ContentTypeID=1</link><pubDate>Fri, 23 Oct 2020 16:40:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da9de8a6-c0ca-4b1d-8e0c-110b948dbf33</guid><dc:creator>astella</dc:creator><description>&lt;p&gt;Thank you Vidar Berg very much, now it is much more clear to me:&lt;/p&gt;
&lt;p&gt;In sdk16 we had to keep track of latest pm_peer_id (&lt;span&gt;pm_peer_id_get after a new connection&lt;/span&gt;) save in flash using fds and use it as a parameter to&amp;nbsp;&lt;span&gt;pm_peer_data_bonding_load when starting a new directed advertisement.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Please note that when inserting a passkey, pm_peer_id is invalid, but with very little of magic using Nordic&amp;nbsp;pm_peer_count it is very simple to sort everything out.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: best way to retrieve latest used BLE bonding infos using SDK16 peer manager library</title><link>https://devzone.nordicsemi.com/thread/276470?ContentTypeID=1</link><pubDate>Thu, 22 Oct 2020 14:09:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62133171-03be-4065-b50e-93fc56cf2587</guid><dc:creator>astella</dc:creator><description>&lt;p&gt;Thank you very much Vidar Berg.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;quot;&lt;span&gt;Directed advertising is usually targeted towards the last connected GAP central, so all you really need to keep track of is one peer id.&amp;nbsp;&lt;/span&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;At the moment we are using sdk16 and ble_advertising_start(&amp;amp;m_advertising,BLE_ADV_MODE_DIRECTED_HIGH_DUTY) so to successfully start directed adv.&lt;/p&gt;
&lt;p&gt;We want to trigger that routine with&amp;nbsp;&lt;span&gt;BLE_ADV_MODE_DIRECTED_HIGH_DUTY parameter, only if last connection is still a valid bond.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Otherwise, we want to trigger ble_advertising_start using&amp;nbsp;BLE_ADV_MODE_FAST.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;We are putting to the test something like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Function for initializing the Advertising functionality. */
static void advertising_init(void) 
{
	uint32_t err_code;
	uint8_t adv_flags;
	ble_advertising_init_t init;

	memset(&amp;amp;init, 0, sizeof(init));

	adv_flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
	init.advdata.name_type = BLE_ADVDATA_FULL_NAME;
	init.advdata.include_appearance = true;
	init.advdata.flags = adv_flags;
	init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
	init.advdata.uuids_complete.p_uuids = m_adv_uuids;

        #if SWIFT_PAIR_SUPPORTED == 1
        init.advdata.p_manuf_specific_data = &amp;amp;m_sp_manuf_advdata;
        memcpy(&amp;amp;m_sp_advdata, &amp;amp;init.advdata, sizeof(m_sp_advdata));
        #endif

	init.config.ble_adv_whitelist_enabled = true;
	init.config.ble_adv_directed_high_duty_enabled = true;
	init.config.ble_adv_directed_enabled = true;
	init.config.ble_adv_directed_interval = APP_ADV_FAST_INTERVAL;
	init.config.ble_adv_directed_timeout = APP_ADV_FAST_DURATION;
	init.config.ble_adv_fast_enabled = true;
	init.config.ble_adv_fast_interval = APP_ADV_FAST_INTERVAL;
	init.config.ble_adv_fast_timeout = APP_ADV_FAST_DURATION;
	init.config.ble_adv_slow_enabled = true;
	init.config.ble_adv_slow_interval = APP_ADV_SLOW_INTERVAL;
	init.config.ble_adv_slow_timeout = APP_ADV_SLOW_DURATION;

	init.evt_handler = on_adv_evt;
	init.error_handler = ble_advertising_error_handler;

	err_code = ble_advertising_init(&amp;amp;m_advertising, &amp;amp;init);
	APP_ERROR_CHECK(err_code);

	ble_advertising_conn_cfg_tag_set(&amp;amp;m_advertising, APP_BLE_CONN_CFG_TAG);
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Then:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Function for starting advertising. */
pm_peer_data_bonding_t bonding_data;
pm_peer_data_bonding_t * p_data = &amp;amp;bonding_data;
void StartAdvertising(void *p_erase_bonds) 
{
	bool erase_bonds = *(bool *)p_erase_bonds;

	if(erase_bonds) 
	{
		DeleteBonds();
		// Advertising is started by PM_EVT_PEERS_DELETE_SUCCEEDED event.
	}
	else 
	{
            //LastConnectionIndexRead(&amp;amp;connIndex);
            if(pm_peer_count() &amp;gt; 0)
            {                  
                // there are valid peers
                pm_peer_data_bonding_load((pm_peer_id_t) 0, p_data);
                //NRF_LOG_INFO(&amp;quot;ble retrieved index: %x&amp;quot;, connIndex);

                NRF_LOG_INFO(&amp;quot;ADV_DIRECTED_IND&amp;quot;);
                NRF_LOG_INFO(&amp;quot;PEER BLE ADDRESS: &amp;quot;);
                NRF_LOG_HEXDUMP_INFO(p_data-&amp;gt;peer_ble_id.id_addr_info.addr, 6);

                ret_code_t err_code = ble_advertising_start(&amp;amp;m_advertising, BLE_ADV_MODE_DIRECTED_HIGH_DUTY);
                APP_ERROR_CHECK(err_code);
            }
            else
            {
                 NRF_LOG_INFO(&amp;quot;ADV_IND&amp;quot;);
                 whitelist_set(PM_PEER_ID_LIST_SKIP_NO_ID_ADDR);

                 ret_code_t err_code = ble_advertising_start(&amp;amp;m_advertising, BLE_ADV_MODE_FAST);
                 APP_ERROR_CHECK(err_code);                     
            }
	}
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Does it makes sense? Basically here we are doing adv_ind if there are no valid bonding entries, otherwise we start high duty directed advertising. Is it formally correct according to your experience and sdk16?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If not, what would be the better way to proceed?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: best way to retrieve latest used BLE bonding infos using SDK16 peer manager library</title><link>https://devzone.nordicsemi.com/thread/276446?ContentTypeID=1</link><pubDate>Thu, 22 Oct 2020 12:51:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2faaf0c4-94cd-435b-b4d6-d260ee505df7</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Directed advertising is usually targeted towards the last connected GAP central, so all you really need to keep track of is one peer id. The ble_app_hids_* examples in SDK 17 demonstrates how this adv. mode can be implemented.&lt;/p&gt;
[quote user=""]When doing directed advertising yesterday I noticed that over about 20 tries, the internal prototype&amp;nbsp; experienced a couple of resets. I don&amp;#39;t know if it is a software issue or an energetic one (could you briefly argument something about that please).[/quote]
&lt;p&gt;&amp;nbsp;The most common reason for sudden resets are code assertions. I suggest you build the project with the &amp;quot;DEBUG&amp;quot; flag to trap all errors instead of letting the &lt;span&gt;&lt;a title="Error module" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/lib_error.html?cp=7_1_3_13"&gt;Error module&lt;/a&gt;&lt;/span&gt; reset the device. Do you have debug logging enabled to see if any errors are reported?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>