<?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>Bonding problem with cheap BLE sensor and nRF DK52</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/69255/bonding-problem-with-cheap-ble-sensor-and-nrf-dk52</link><description>I am developing a CSCS client on my nRF52 DK and have two sensors at hand to test my implementation. Softdevice S132, SDK 17.0.2 
 My code is based on $SDKROOT\examples\ble_central_and_peripheral\experimental\ble_app_hrs_rscs_relay with SDK 17.0.2 
 Though</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 06 Jan 2021 16:32:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/69255/bonding-problem-with-cheap-ble-sensor-and-nrf-dk52" /><item><title>RE: Bonding problem with cheap BLE sensor and nRF DK52</title><link>https://devzone.nordicsemi.com/thread/287788?ContentTypeID=1</link><pubDate>Wed, 06 Jan 2021 16:32:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:573e0ae4-e224-4f9b-b510-f465a81ff4ce</guid><dc:creator>daubsi</dc:creator><description>&lt;p&gt;Awesome! That did the trick! It now works as expected!! On Connection error, it disconnects, removes the peers and reconnects!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding problem with cheap BLE sensor and nRF DK52</title><link>https://devzone.nordicsemi.com/thread/287524?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2021 13:35:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c47dd8a0-7d07-490d-8ae7-1beaf7697247</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I discussed this with a colleague, and they spotted something important that I missed when looking at your pm_evt_handler();.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        case PM_EVT_PEERS_DELETE_SUCCEEDED:
            need_peer_delete = false;
            adv_scan_start();
            break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The problem seems to be that when you get the PEERS_DELETE_SUCCEEDED event, you start the scan right away, however this event doesn&amp;#39;t mean that the connection is already in the DISCONNECTED state. It will take a connection interval of time, or a &amp;quot;manual&amp;quot; disconnection for the SoftDevice to get the acknowledgement of this, so you should move the adv_scan_start(); function to your DISCONNECTED event instead.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding problem with cheap BLE sensor and nRF DK52</title><link>https://devzone.nordicsemi.com/thread/287455?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2021 10:20:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a8ec91a-2b53-4594-abae-69a67138f044</guid><dc:creator>daubsi</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;yes, I saw the way you do it in the advertising_start() but the thing is that this has already started in the &lt;span&gt;ble_app_hrs_rscs_relay? I am scanning for the peripherals in the &amp;quot;backend&amp;quot; (the true BLE peripherals like the HRS) and offering the services in the &amp;quot;frontend&amp;quot; (e.g. to a smartphone). When there is now a problem while connecting in the backend to one of the sensors I might be able to disconnect there but not from a potentially already connected frontend device - though - in my tests not even that was the case, that there was already a connection.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So ofc I COULD just delete the peer information every time when I power on the device/restart the app but I would rather prefer a more clean variant, where it is only done when it is really needed? Like: trying to connect to backend service. Oops, bonding problem, disconnect, delete peer data, rescan/reconnect. I understand this would be the process I implmented. Nevertheless it faults with &amp;quot;INVALID_STATE&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;need_peer_delete is just a boolean var that I set to true in (see above)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;...
...
case PM_EVT_CONN_SEC_FAILED:
            //NRF_LOG_INFO(&amp;quot;Establishing a secure link by Peer Manager failed! Please press Button 2 + RESET on the DK to delete bonding data&amp;quot;);
            NRF_LOG_INFO(&amp;quot;Establishing a secure link by Peer Manager failed! Trying to remove bonds and rescan&amp;quot;);
            need_peer_delete = true;
            //delete_bonds();
            break;
            
...&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;and that I am checking for in the BLE event handler too, to be sure it is exactly that event which gets triggered.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;...
if ((p_gap_evt-&amp;gt;params.disconnected.reason == BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION) &amp;amp;&amp;amp; need_peer_delete)
...            &lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;(meaning, the PM actually really disconnects and throws an event with &amp;quot;BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION&amp;quot; reason.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I suspected I would be able to call the delete_bonds() there safely... (&amp;quot;delete_bonds()&amp;quot; is just the same function you too have in your examples)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Is it possible what I try to achieve?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding problem with cheap BLE sensor and nRF DK52</title><link>https://devzone.nordicsemi.com/thread/287420?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2021 08:44:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aafab1e2-94ca-4b19-a49b-72b7d2377fd0</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;If you check out our other examples, we generally call the delete_bonds(); function at the start of the advertising_start() functions in most of our ble_peripheral examples. Keep in mind that you need to disconnect from the peer before you call advertising_start(). How does the &amp;quot;need_peer_delete&amp;quot; function you have created look?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding problem with cheap BLE sensor and nRF DK52</title><link>https://devzone.nordicsemi.com/thread/287344?ContentTypeID=1</link><pubDate>Mon, 04 Jan 2021 20:21:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e69cabf-a108-4c0d-b9cc-316dbbafe23a</guid><dc:creator>daubsi</dc:creator><description>&lt;p&gt;Hi Simon,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;this is exactly still the problem I am still facing:&lt;/p&gt;
&lt;p&gt;This is my current pm_evt_handler&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void pm_evt_handler(pm_evt_t const * p_evt)
{
    pm_handler_on_pm_evt(p_evt);
    pm_handler_disconnect_on_sec_failure(p_evt);
    pm_handler_flash_clean(p_evt);

    switch (p_evt-&amp;gt;evt_id)
    {
        case PM_EVT_PEERS_DELETE_SUCCEEDED:
            need_peer_delete = false;
            adv_scan_start();
            break;
        case PM_EVT_CONN_SEC_FAILED:
            //NRF_LOG_INFO(&amp;quot;Establishing a secure link by Peer Manager failed! Please press Button 2 + RESET on the DK to delete bonding data&amp;quot;);
            NRF_LOG_INFO(&amp;quot;Establishing a secure link by Peer Manager failed! Trying to remove bonds and rescan&amp;quot;);
            need_peer_delete = true;
            //delete_bonds();
            break;
        case PM_EVT_CONN_SEC_CONFIG_REQ:
          {
            // Allow pairing request from an already bonded peer.
            pm_conn_sec_config_t conn_sec_config = {.allow_repairing = true};            
            pm_conn_sec_config_reply(p_evt-&amp;gt;conn_handle, &amp;amp;conn_sec_config);
          }break;
        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;As you can say I asked pm to disconnect&lt;/p&gt;
&lt;p&gt;Then I tried in&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void on_ble_central_evt(ble_evt_t const * p_ble_evt)
{
...
...
case BLE_GAP_EVT_DISCONNECTED:
        {
            
            if (p_gap_evt-&amp;gt;conn_handle == m_conn_handle_hrs_c)
            {
                ...
            }
            
            if (p_gap_evt-&amp;gt;conn_handle == m_conn_handle_cscs_c)
            {
                ...
            }

            // This one triggers by PM
            if ((p_gap_evt-&amp;gt;params.disconnected.reason == BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION) &amp;amp;&amp;amp; need_peer_delete)
            {
                    NRF_LOG_INFO(&amp;quot;Disconnected due to sec failure. Deleting peers.&amp;quot;);
                    delete_bonds();
                    need_peer_delete = false;
            }
            ...
            &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Because that looked like the proper place?&lt;/p&gt;
&lt;p&gt;It also DOES delete the bonds but crashes again with an INVALID_STATE.&lt;/p&gt;
&lt;p&gt;If this is still not the proper place, kindly give me a very brief best-practice example how to do it. My code is based on&amp;nbsp;ble_app_hrs_rscs_relay.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding problem with cheap BLE sensor and nRF DK52</title><link>https://devzone.nordicsemi.com/thread/287237?ContentTypeID=1</link><pubDate>Mon, 04 Jan 2021 13:11:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b1ae9cb-9f68-4066-887b-9ebf99255663</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;The INVALID_STATE error when you start advertising points to the device thinking it still is in a connection or already is advertising. Please make sure that you disconnect&amp;nbsp;before deleting the peers.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding problem with cheap BLE sensor and nRF DK52</title><link>https://devzone.nordicsemi.com/thread/286567?ContentTypeID=1</link><pubDate>Thu, 24 Dec 2020 15:35:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2fc689ac-646f-4956-98a0-0abcb4dc3a89</guid><dc:creator>daubsi</dc:creator><description>&lt;p&gt;Simon, I was just trying to do the peer removal as suggested, but when I now call delete_bonds() inside of pm_evt_handler() (which basically just calls&amp;nbsp;pm_peers_delete()), I get an error&amp;nbsp;&lt;/p&gt;
&lt;p&gt;[00:00:00.905,151] &amp;lt;info&amp;gt; peer_manager_handler: Connection security failed: role: Central, conn_handle: 0x0, procedure: Encryption, error: 4102&lt;br /&gt;[00:00:00.905,944] &amp;lt;warning&amp;gt; peer_manager_handler: Disconnecting conn_handle 0.&lt;br /&gt;[00:00:00.906,372] &amp;lt;info&amp;gt; app: Establishing a secure link by Peer Manager failed! Trying to remove bonds and rescan&lt;br /&gt;[00:00:00.907,043] &amp;lt;info&amp;gt; app: Erase bonds!&lt;br /&gt;[00:00:00.910,034] &amp;lt;error&amp;gt; peer_manager_handler: Peer deleted successfully: peer_id: 0&lt;br /&gt;[00:00:00.910,461] &amp;lt;info&amp;gt; peer_manager_handler: All peers deleted.&lt;br /&gt;[00:00:00.910,888] &amp;lt;error&amp;gt; app: ERROR 8 [NRF_ERROR_INVALID_STATE] at D:\nRF5_SDK_17.0.2_d674dde\xxxx\main.c:439&lt;br /&gt;PC at: 0x00031D51&lt;/p&gt;
&lt;p&gt;Line 439 is the last APP_ERROR_CHECK in:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void adv_scan_start(void)
{
    ret_code_t err_code;

    //check if there are no flash operations in progress
    if (!nrf_fstorage_is_busy(NULL))
    {
        // Start scanning for peripherals and initiate connection to devices which
        // advertise Heart Rate or Cycling speed and cadence UUIDs.
        scan_start();

        // Turn on the LED to signal scanning.
        bsp_board_led_on(CENTRAL_SCANNING_LED);

        // Start advertising.
        err_code = ble_advertising_start(&amp;amp;m_advertising, BLE_ADV_MODE_FAST);
        APP_ERROR_CHECK(err_code);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;(i.e. checking the return value from ble_advertising_start()). What&amp;#39;s the proper way of doing the peer delete and restarting the whole scan process, please?&lt;/p&gt;
&lt;p&gt;BR&lt;br /&gt;Markus&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void pm_evt_handler(pm_evt_t const * p_evt)
{
pm_handler_on_pm_evt(p_evt);
pm_handler_disconnect_on_sec_failure(p_evt);
pm_handler_flash_clean(p_evt);

switch (p_evt-&amp;gt;evt_id)
{
case PM_EVT_PEERS_DELETE_SUCCEEDED:
adv_scan_start();
break;
case PM_EVT_CONN_SEC_FAILED:
//NRF_LOG_INFO(&amp;quot;Establishing a secure link by Peer Manager failed! Please press Button 2 + RESET on the DK to delete bonding data&amp;quot;);
NRF_LOG_INFO(&amp;quot;Establishing a secure link by Peer Manager failed! Trying to remove bonds and rescan&amp;quot;);
delete_bonds();
break;
default:
break;
}
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding problem with cheap BLE sensor and nRF DK52</title><link>https://devzone.nordicsemi.com/thread/284257?ContentTypeID=1</link><pubDate>Thu, 10 Dec 2020 08:56:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:133b4b5b-81c5-49c3-931b-7da492e394e0</guid><dc:creator>daubsi</dc:creator><description>&lt;p&gt;Thank you! I wasn&amp;#39;t sure about &amp;quot;&lt;span&gt;I&amp;#39;m sorry, but for this specific issue, there is nothing you can do in the central except deleting bond information on the central side as well and pair/bond again.&amp;quot; but now that you confirm that&amp;#39;s the only option I&amp;#39;ll go for this one! Have a great day!&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding problem with cheap BLE sensor and nRF DK52</title><link>https://devzone.nordicsemi.com/thread/284252?ContentTypeID=1</link><pubDate>Thu, 10 Dec 2020 08:47:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:206126b1-7cbf-4778-b112-72c95b2afce5</guid><dc:creator>Simonr</dc:creator><description>[quote user="daubsi"]Just to understand this correctly: The error occurs because.... the DK still knows the key and tries to encrypt the channel but the peripheral says &amp;quot;I don&amp;#39;t know what you&amp;#39;re talking about&amp;quot; and shuts down the connection?[/quote]
&lt;p&gt;&amp;nbsp;That&amp;#39;s correct, the peripheral has lost the LTK for some reason, this could be that it has its own &amp;quot;delete bonding&amp;quot; that is called for some reason where it shouldn&amp;#39;t, or that this key is stored somewhere it is prone to being deleted. I&amp;#39;m sorry, but for this specific issue, there is nothing you can do in the central except deleting bond information on the central side as well and pair/bond again.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding problem with cheap BLE sensor and nRF DK52</title><link>https://devzone.nordicsemi.com/thread/284095?ContentTypeID=1</link><pubDate>Wed, 09 Dec 2020 13:59:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b203ec3a-e8b1-40ad-b543-486397f05f06</guid><dc:creator>daubsi</dc:creator><description>&lt;p&gt;Dear Simonr,&lt;/p&gt;
&lt;p&gt;my bad - I should have actually included the relevant log lines with error 4352 as well. Anyway, they exist and it seems it&amp;#39;s either 4352, 4102 or a combination thereof.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes, deleting the bonding information is what I just did for the last couple of weeks, but it&amp;#39;s kinda cumbersome and I was wondering if there isn&amp;#39;t a better way to handle this? The vendor is from the Asia reagion. I can ofc get in touch with him but I have little hope they can actually help me here... as people say &amp;quot;Buy cheap, buy twice&amp;quot; :-/&lt;/p&gt;
&lt;p&gt;Just to understand this correctly: The error occurs because.... the DK still knows the key and tries to encrypt the channel but the peripheral says &amp;quot;I don&amp;#39;t know what you&amp;#39;re talking about&amp;quot; and shuts down the connection? So the question would be WHY the peripheral loses the key. I&amp;#39;ve put fresh batteries in and all that, so it shouldn&amp;#39;t be a power supply thing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding problem with cheap BLE sensor and nRF DK52</title><link>https://devzone.nordicsemi.com/thread/284075?ContentTypeID=1</link><pubDate>Wed, 09 Dec 2020 13:32:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88c36dad-a842-4408-b0ff-b09d0fa6d93d</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;This sounds very strange. I&amp;#39;m not able to see that error 4352 is triggered anywhere in your log, but error 4102 is indeed a faulty or missing pin/key. This means that encryption has failed because the peripheral has lost the LTK for this bond. This issue should be fixed by deleting bond information on the central as well. You could, for example make your central device delete its bonding information whenever it runs into this error and start scanning again.&lt;/p&gt;
&lt;p&gt;Alternatively, try contacting the manufacturers of the sensor you got (if possible), and ask if this is something they&amp;#39;re aware of and have a firmware update available for.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>