<?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>proper usage of peer manager + advertising and what to do after disconnect</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/124151/proper-usage-of-peer-manager-advertising-and-what-to-do-after-disconnect</link><description>I am using NRF SDK 17.1.0 
 I inherited some legacy code that was a mess, and rewrote it. 
 Part 1 - 
 First I skipped the peer manager thinking it was not necessary. Then I re-added the peer manager to a peripheral to allow faster reconnects in the event</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 18 Sep 2025 20:26:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/124151/proper-usage-of-peer-manager-advertising-and-what-to-do-after-disconnect" /><item><title>RE: proper usage of peer manager + advertising and what to do after disconnect</title><link>https://devzone.nordicsemi.com/thread/549233?ContentTypeID=1</link><pubDate>Thu, 18 Sep 2025 20:26:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e83eb31-5d24-4f78-9339-2008a4f17e08</guid><dc:creator>ms360</dc:creator><description>&lt;p&gt;The submerged peripheral was triggering the disconnect count / time threshold I previously tried. It happens pretty quickly with 1 foot of water separating the devices. It looked like the prescribed fix for the sec_failure from last week. They both have a very similar failure mode.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I did get it working with peripheral BLE advertisements showing a flag in advertisement data, and the central gives up after seeting the flag, trying N tries and deletes the bonds. It helped a lot. The solution you&amp;#39;re providing would simplify things quite a bit tho.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think either is viable. Yours wont require updating BLE documentation.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: proper usage of peer manager + advertising and what to do after disconnect</title><link>https://devzone.nordicsemi.com/thread/549228?ContentTypeID=1</link><pubDate>Thu, 18 Sep 2025 19:35:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2551c861-7dc6-403b-b7bb-6d0f9293a932</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;I tested a little bit with the &lt;a href="https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/ble_sdk_app_hrs.html"&gt;ble_app_hrs&lt;/a&gt;&amp;nbsp;and &lt;a href="https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/ble_sdk_app_hrc.html"&gt;ble_app_hrs_c&lt;/a&gt; examples and have a few findings.&lt;/p&gt;
&lt;p&gt;First, I found that the disconnection in those examples&amp;nbsp;is due to a&amp;nbsp;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;pm_handler_disconnect_on_sec_failure()&lt;/span&gt; call in the peer manager event handler. A failure in the security procedure doesn&amp;#39;t immediately lead to a disconnection.&lt;/p&gt;
&lt;p&gt;Thus, I comment out&amp;nbsp;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;pm_handler_disconnect_on_sec_failure()&lt;/span&gt;, and retry the case where only the peripheral forgets the bond.&lt;br /&gt;I see that both the central and the peripheral receive error 4102 with different source.&lt;br /&gt;On the central, Peer Manager report error 4102 with &lt;a href="https://docs.nordicsemi.com/bundle/s140_v7.2.0_api/page/group_b_l_e_g_a_p_s_e_c_s_t_a_t_u_s_s_o_u_r_c_e_s.html"&gt;source&lt;/a&gt; BLE_GAP_SEC_STATUS_SOURCE_REMOTE.&lt;br /&gt;On the peripheral, Peer Manager reports error 4102 with source&amp;nbsp;BLE_GAP_SEC_STATUS_SOURCE_LOCAL.&lt;/p&gt;
&lt;p&gt;If your application is also using&amp;nbsp;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;pm_handler_disconnect_on_sec_failure()&lt;/span&gt;, you can try delaying that call until after error checking, detect the error, and raise some flags&amp;nbsp;before disconnecting, for example.&lt;/p&gt;
&lt;p&gt;On a relevant note, if I also remove the auto disconnect, and try the case where only the central forgets the bond, both devices then see Peer Manager reporting error 133, &lt;a href="https://docs.nordicsemi.com/bundle/s140_v7.2.0_api/page/group_b_l_e_g_a_p_s_e_c_s_t_a_t_u_s.html#ga87ed8db7604006675930bdf5fa79ae70"&gt;BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP&lt;/a&gt;.&amp;nbsp;That&amp;nbsp;sounds arguably wrong, but it is what the current behavior is like. If you wish, you can add similar handling on the peripheral side to forget bonds.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;While&amp;nbsp;working on that, I realize something strange. How come the submerged peripheral device forgets the bonds? Does it get bonded with a lot of centrals?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: proper usage of peer manager + advertising and what to do after disconnect</title><link>https://devzone.nordicsemi.com/thread/549210?ContentTypeID=1</link><pubDate>Thu, 18 Sep 2025 15:38:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f79c9d76-1ffa-491a-a34f-0446e1e9a971</guid><dc:creator>ms360</dc:creator><description>&lt;p&gt;I added this exact feature, and now the central can filter scanned devices for the &amp;quot;peripheral with 4102&amp;quot; indicator and delete bonds.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: proper usage of peer manager + advertising and what to do after disconnect</title><link>https://devzone.nordicsemi.com/thread/549085?ContentTypeID=1</link><pubDate>Wed, 17 Sep 2025 18:31:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03ac4978-0404-4ab0-9807-28e5a66f0e83</guid><dc:creator>ms360</dc:creator><description>&lt;p&gt;So I did try this, and it did fix the central reconnecting problem.&amp;nbsp;&lt;br /&gt;However it broke the tolerance to being submerged.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;We frequently submerge the device, which is why I used peer manager in the first place, for quick reconnection, and it worked great.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The second I implemented the workaround (3x within 10-15 seconds), after submerging, I have to re-pair, which is not good at all.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Since the central doesn&amp;#39;t see the 4102, maybe I need to update peripheral advertisement data to indicate to the central to clear the bonding info, when it see&amp;#39;s a 4102. Can you think of anything simpler?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: proper usage of peer manager + advertising and what to do after disconnect</title><link>https://devzone.nordicsemi.com/thread/548509?ContentTypeID=1</link><pubDate>Thu, 11 Sep 2025 13:40:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a410afba-cce9-4c58-a46b-9da3e53f38d2</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;If you want the central to delete the bond, then you could implement a simple logic where if the connection failed repeatedly within a small time frame (like more than 3 times within 10-15 seconds), it could delete the bond.&lt;/p&gt;
&lt;p&gt;Deleting bond on the central could be done similar to how it is done in the peripheral.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: proper usage of peer manager + advertising and what to do after disconnect</title><link>https://devzone.nordicsemi.com/thread/548382?ContentTypeID=1</link><pubDate>Wed, 10 Sep 2025 14:01:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d14da887-7332-4fa6-9449-b6466bf88fb1</guid><dc:creator>ms360</dc:creator><description>&lt;p&gt;The central device is another nrf52840.&amp;nbsp;&lt;br /&gt;It does not see the error 4102 warning, it only see&amp;#39;s the disconnect reason 0x13.&lt;br /&gt;The peripheral show&amp;#39;s the error 4102 warning.&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;It would be better if the central could detect this issue and delete the bonds.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: proper usage of peer manager + advertising and what to do after disconnect</title><link>https://devzone.nordicsemi.com/thread/548362?ContentTypeID=1</link><pubDate>Wed, 10 Sep 2025 12:10:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:72386760-1069-4bfa-a611-969e2025c9b0</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi ms360,&lt;/p&gt;
&lt;p&gt;What is the central device? Are there no way to delete the bond information from it?&lt;/p&gt;
&lt;p&gt;If you try to connect to the nRF device using a new central, such as your phone, do you still get the error 4102?&lt;/p&gt;
&lt;p&gt;Regarding the LOG_ERROR on the default case, I recommend lowering it down to the NRF_LOG_INFO or NRF_LOG_WARNING level and maybe change the message. It just signifies unhandled &lt;a href="https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/group_peer_manager.html#ga4a0e37cf07eb91e1a1808995b957808b"&gt;PM events&lt;/a&gt;, not an error.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: proper usage of peer manager + advertising and what to do after disconnect</title><link>https://devzone.nordicsemi.com/thread/548253?ContentTypeID=1</link><pubDate>Tue, 09 Sep 2025 14:09:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:35309630-dd35-4703-8ce5-ac7d5b0950df</guid><dc:creator>ms360</dc:creator><description>&lt;p&gt;Thank you Hieu.&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I still get the error 4102 because my central cannot identify a regular disconnect from a security failure.&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;The central doesn&amp;#39;t seem to know it was &amp;#39;hung up on&amp;#39; regarding a pair auth failure.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;All I can find so far is&amp;nbsp;&lt;span&gt;BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The PM Errors came from the default case in the pm_evt_handler&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void pm_evt_handler(pm_evt_t const * p_evt)
{
    pm_handler_on_pm_evt(p_evt);
    if (p_evt-&amp;gt;conn_handle == BondedDevice_handle) { 
        pm_handler_disconnect_on_sec_failure(p_evt);
    }
    pm_handler_flash_clean(p_evt);
    
    ret_code_t err_code;
    switch (p_evt-&amp;gt;evt_id)
    {


        case PM_EVT_PEERS_DELETE_SUCCEEDED:
            // Bonds are deleted. Start scanning.
            scan_start();
            break;
        case PM_EVT_CONN_SEC_FAILED:
            NRF_LOG_ERROR(&amp;quot;PM_EVT_CONN_SEC_FAILED&amp;quot;);
            break;
        default:
            NRF_LOG_ERROR(&amp;quot;PM ERROR %d&amp;quot;, p_evt-&amp;gt;evt_id);
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: proper usage of peer manager + advertising and what to do after disconnect</title><link>https://devzone.nordicsemi.com/thread/548187?ContentTypeID=1</link><pubDate>Tue, 09 Sep 2025 09:30:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25f1d5cc-d379-4361-9134-ba2aae5b0af7</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi ms360,&lt;/p&gt;
&lt;p&gt;Is the Peer Manager error&amp;nbsp;4102 still an issue or not?&lt;/p&gt;
&lt;p&gt;On the nRF device, you can delete bonds using the &lt;a href="https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/group_peer_manager.html#gaa99779ab5b8b4cfde65974bdf75a1e7c"&gt;pm_peers_delete()&lt;/a&gt;&amp;nbsp;function.&lt;/p&gt;
&lt;p&gt;Regarding the above log, what are the things that produce the &amp;quot;PM ERROR &amp;lt;err num&amp;gt;&amp;quot; lines?&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: proper usage of peer manager + advertising and what to do after disconnect</title><link>https://devzone.nordicsemi.com/thread/548108?ContentTypeID=1</link><pubDate>Mon, 08 Sep 2025 20:06:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11295b28-17a2-49a8-87a3-503a74b12510</guid><dc:creator>ms360</dc:creator><description>&lt;p&gt;Hieu, thank you. That sounds like the exact issue. I&amp;#39;m trying to detect this on the central but I&amp;#39;m not getting a clear event to indicate. Other than&amp;nbsp;&amp;nbsp;&lt;span&gt;BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0x13&lt;/span&gt;&lt;span&gt; /**&amp;lt; Remote User Terminated Connection. */&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I logged all the PM events and I don&amp;#39;t see an auth or sec failure. Is there something I can trigger the bonding info delete on?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[00:00:55.023,498] &amp;lt;error&amp;gt; ble_scan: Paired Peripheral FOUND with RSSI: -19 max: -23
[00:00:55.023,803] &amp;lt;info&amp;gt; ble_scan: Connecting
[00:00:55.067,626] &amp;lt;info&amp;gt; app: Connecting to target 079258EAD4E1
[00:00:55.067,687] &amp;lt;error&amp;gt; app: PM ERROR 1
[00:00:55.067,871] &amp;lt;error&amp;gt; app: PM ERROR 6
[00:00:55.068,237] &amp;lt;error&amp;gt; app: PM ERROR 2
[00:00:55.068,237] &amp;lt;info&amp;gt; peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update, no change
[00:00:55.068,298] &amp;lt;error&amp;gt; app: PM ERROR 9
[00:00:55.068,298] &amp;lt;error&amp;gt; app: PM ERROR 0
[00:00:55.068,908] &amp;lt;error&amp;gt; app: PM ERROR 15&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: proper usage of peer manager + advertising and what to do after disconnect</title><link>https://devzone.nordicsemi.com/thread/547975?ContentTypeID=1</link><pubDate>Fri, 05 Sep 2025 21:04:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc37b4bb-ed40-4c23-8455-78eebca7b52e</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi ms360,&lt;/p&gt;
[quote user=""]Question 1&amp;amp;2 - is this the correct way to handle advertise on disconnect? Should I never be turning off advertising after a connection is established?&amp;nbsp;[/quote]
&lt;p&gt;There are multiple things at play here so let me go into it a bit slowly.&lt;/p&gt;
[quote user=""]I set config&lt;span&gt;.&lt;/span&gt;&lt;span&gt;ble_adv_on_disconnect_disabled to&amp;nbsp;false&lt;/span&gt;[/quote]
&lt;p&gt;It seems you are using &lt;a href="https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/lib_ble_advertising.html"&gt;the Advertising Module&lt;/a&gt; here rather than direct &lt;a href="https://docs.nordicsemi.com/bundle/s140_v7.2.0_api/page/group_b_l_e_g_a_p_f_u_n_c_t_i_o_n_s.html#ga74c21287bd6cbcd5822bc73792f678d8"&gt;SoftDevice GAP API&lt;/a&gt;. No problem with that, just&amp;nbsp;noting details for later.&lt;/p&gt;
&lt;p&gt;The exact behavior desired depends on your requirements. However, most project would like to have the device restart advertising upon disconnection. Regardless, this shouldn&amp;#39;t have any issue related to pairing.&lt;/p&gt;
[quote user=""]The legacy code I inherited never turned off advertising, tho I don&amp;#39;t see it advertise in nrf connect while connected[/quote]
&lt;p&gt;Connectable advertising&amp;nbsp;is stopped once the connection request is received. This is the default behavior.&lt;/p&gt;
&lt;p&gt;Do you expect the&amp;nbsp;connectable advertising to continue? Is the device expected to support multiple concurrent centrals?&lt;/p&gt;
[quote user=""]The legacy code I inherited was skipping&amp;nbsp;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;pm_handler_disconnect_on_sec_failure in the pm_evt_handler(), I re-enabled it&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;[/quote]
&lt;p&gt;No comment on this. This depends on your requirement.&lt;/p&gt;
[quote user=""]Between these 2 actions, it seems like the cross pairing issue is gone.&amp;nbsp;[/quote]
&lt;p&gt;I need some clarifications here. What exactly is the cross-pairing issue?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Does the issue disappear after you set&amp;nbsp;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;ble_adv_on_disconnect_disabled()&lt;/span&gt; and implement &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;pm_handler_disconnect_on_sec_failure()&lt;/span&gt;? Or after you do either of those?&lt;/p&gt;
[quote user=""]&lt;p&gt;&lt;span&gt;&amp;lt;warning&amp;gt; app: BLE_GAP_EVT_CONNECTED&lt;br /&gt;&amp;lt;info&amp;gt; peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x0, procedure: Encryption, error: 4102&lt;br /&gt;&amp;lt;warning&amp;gt; peer_manager_handler: Disconnecting conn_handle 0.&lt;br /&gt;&amp;lt;warning&amp;gt; app: BLE_GAP_EVT_DISCONNECTED&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I expect the security failure given that it isn&amp;#39;t paired/bonded.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Question 3 - If I delete the bonds on the peripheral, start advertising (undirected) and want this new central to connect, It seems like it stops scanning and fails to connect.&amp;nbsp;&lt;br /&gt;I am trying to determine if this is a bug in my central or the peripheral. Still gathering data. Open to suggestions.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Refer to this past DevZone case:&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/55866/peer_manager_handler-connection-security-failed-role-peripheral-conn_handle-0x0-procedure-encryption-error-4102"&gt;peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x0, procedure: Encryption, error: 4102&lt;/a&gt;&amp;nbsp;.&lt;/p&gt;
&lt;p&gt;The steps you described here matches what is discussed in that case, where the bond information is only deleted on one device. If the other device isn&amp;#39;t programmed to clear the bond information on this kind of failure, the failure will persist.&lt;/p&gt;
&lt;p&gt;Could that be the case?&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>