<?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>peer_id,conn_handle and check connection</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/112419/peer_id-conn_handle-and-check-connection</link><description>I&amp;#39;m organizing my code with nRF SDK v17.0.0,using the board nRF52832 that designed by myself. 
 In order to support multi-central,the peer_manager module is used.So that I can use peer_id and conn_handle to get another one. 
 Such as I will save peer_id</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 27 Jun 2024 12:49:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/112419/peer_id-conn_handle-and-check-connection" /><item><title>RE: peer_id,conn_handle and check connection</title><link>https://devzone.nordicsemi.com/thread/491111?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2024 12:49:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bdfe930a-1157-4dd6-bc00-0a3c4558924a</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;To delay some things in nRF5 SDK, the typical way is to use a shingle shot &lt;a href="https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/lib_timer.html"&gt;app_timer&lt;/a&gt;. (I am stil struggling&amp;nbsp;a bit to see why you do it this way, starting with the peer_id, instead of relating to the conn_handle you get with the connection event, though. I would think it would be easier to do it the other way around).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: peer_id,conn_handle and check connection</title><link>https://devzone.nordicsemi.com/thread/491103?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2024 12:15:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:185359d4-7bb6-450f-a526-3c46c4ca5619</guid><dc:creator>Chaoyue Ying</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You suggest that I can try a bit later.So which method you suggest?By timer or other ways?The bit later seem hard to fix a time so that I should use the timeout way to check?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: peer_id,conn_handle and check connection</title><link>https://devzone.nordicsemi.com/thread/491098?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2024 12:06:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02abae4c-bc30-4f79-9ad1-1241f416f19b</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;If&amp;nbsp;pm_conn_handle_get() gives you&amp;nbsp;BLE_CONN_HANDLE_INVALID that means that either you have not connection with that peer at that time, or that the peer manger has not processed the new connection yet (or dependign on priorities etc that the peer manager has not processed the new connection yet, and if so you can try a bit later).&lt;/p&gt;
[quote user="Chaoyue Ying"]I think it is necessary that make sure get correct conn_handle everytime.[/quote]
&lt;p&gt;Definetly. Therefore, please note that the conn_handle you get with the connected event and all other evetns are always valid (at the time of the generation of the event). But as in any real time system, things can change over time. So you need to handle that a valid conn_handle may suddently be invalid (due to a disconnect for some reason), etc.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: peer_id,conn_handle and check connection</title><link>https://devzone.nordicsemi.com/thread/490971?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2024 00:36:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a04372c0-7e8b-48ff-87c5-2188da628421</guid><dc:creator>Chaoyue Ying</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I decide to use pm_conn_handle_get() to get conn_handle,but what should I do when pm_conn_handle_get() return&amp;nbsp;&lt;span&gt;BLE_CONN_HANDLE_INVALID?(Because I know the&amp;nbsp;&lt;span&gt;NRF_ERROR_NULL and&amp;nbsp;NRF_ERROR_INVALID_STATE almost do not happened&lt;/span&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I think it is necessary that make sure get correct conn_handle everytime.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span class="yd-translate-container"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span class="yd-translate-container"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="yd-translate-container"&gt;&lt;span class="yd-wrapper-block yd-highlight"&gt;嗨，我决定使用pm_conn_handle_get()来获取conn_handle，但是当pm_conn_handle_get()返回BLE_CONN_HANDLE_INVALID时，我应该做什么?(因为我知道NRF_ERROR_NULL和)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: peer_id,conn_handle and check connection</title><link>https://devzone.nordicsemi.com/thread/490845?ContentTypeID=1</link><pubDate>Wed, 26 Jun 2024 10:56:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ba8c881-2ff0-40ac-8076-c263f7edfb9a</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Chaoyue Ying"]&lt;p&gt;Maybe I not make myself clear,I mean the p_evt-&amp;gt;conn_handle and the conn_hanle that get from pm_conn_hanle_get() should point to the same device.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;The&amp;nbsp;p_evt-&amp;gt;conn_handle is always correct for the event is concerns (though of course it could sometimes be that things have changed between when the event happened and you process it in your application).&lt;/p&gt;
&lt;p&gt;pm_conn_handle_get() is different, as this is a function that lets you look up the conn_handle for a peer based on the peer ID. This can fail for several reasons, and this is documented in the &lt;a href="https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/group__peer__manager.html#ga5f83f99848f22494ee5c231aa5324f61"&gt;API documentaiton&lt;/a&gt;. So you need to check both the return value to verify tha tit is&amp;nbsp;NRF_SUCCESS, as well as check if the conn_handle is&amp;nbsp;BLE_CONN_HANDLE_INVALID. If OK, you got the conn handle to the connection for that peer ID.&lt;/p&gt;
[quote user="Chaoyue Ying"]I think it is unnormal that they are not equal.[/quote]
&lt;p&gt;Yes and no. You have a multi link device, so if you have multiple connections, that may not be the case. And there is also a time factor here. What there is a disconnect (perhaps connection failed to be established due to packet loss), and then a rapid re-connect? You may have an old conn_handle and a new conn handle (with different value) for the same device as there are two different connections. This is something you need to handle.&lt;/p&gt;
[quote user="Chaoyue Ying"]If they are both vaild,that mean BLE support connect a device by both two conn_handle?So that,which one should be used when I want to send data to the device by&amp;nbsp;ble_nus_data_send()?[/quote]
&lt;p&gt;If there is only one connection (?), then both cannot be valid at the same time. But if for instance your application processes the new connection event before the peer manager has processed it, you would get the old conn_handle with&amp;nbsp;pm_conn_handle_get(). So you need to think about how to handle this. Generally, I see no benefit of getting the conn handle via the peer manager (which has to get it by processing a BLE event), instead of getting it from the connected event (and other BLE events). It would probably be better to only consider peer ID when relevant.&lt;/p&gt;
[quote user="Chaoyue Ying"]In my impression,neither p_evt-&amp;gt;conn_handle or pm_conn_handle_get() used in&amp;nbsp;ble_nus_data_send() return NRF_SUCCESS but both no data recived in the peer device.[/quote]
&lt;p&gt;This may be a different issue? Or perhaps you pass the wrong conn_handle to&amp;nbsp;ble_nus_data_send() (it is the last parameter). If you do, I would expect it should return BLE_ERROR_INVALID_CONN_HANDLE.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: peer_id,conn_handle and check connection</title><link>https://devzone.nordicsemi.com/thread/490731?ContentTypeID=1</link><pubDate>Wed, 26 Jun 2024 00:26:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6cf96e14-1003-4764-abd1-a0b3ff4cdc5b</guid><dc:creator>Chaoyue Ying</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Maybe I not make myself clear,I mean the p_evt-&amp;gt;conn_handle and the conn_hanle that get from pm_conn_hanle_get() should point to the same device.&lt;/p&gt;
&lt;p&gt;I think it is unnormal that they are not equal.If they are both vaild,that mean BLE support connect a device by both two conn_handle?So that,which one should be used when I want to send data to the device by&amp;nbsp;ble_nus_data_send()?&lt;/p&gt;
&lt;p&gt;In my impression,neither p_evt-&amp;gt;conn_handle or pm_conn_handle_get() used in&amp;nbsp;ble_nus_data_send() return NRF_SUCCESS but both no data recived in the peer device.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: peer_id,conn_handle and check connection</title><link>https://devzone.nordicsemi.com/thread/490583?ContentTypeID=1</link><pubDate>Tue, 25 Jun 2024 10:43:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d8debf2-093b-4514-9bfe-b406a03a512f</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Chaoyue Ying"]&lt;p&gt;The conn_handle in first line is the value that p_evt-&amp;gt;conn_handle that is return from the p_context of the interrupt and the get handle in third line is the value that&amp;nbsp;get&amp;nbsp; by pm_conn_handle_get().&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure which one is authentic.&lt;/p&gt;[/quote]
&lt;p&gt;The conn_handle you get in&amp;nbsp;p_evt-&amp;gt;conn_handle (you will get this for any evetn related to a connection), reflect which connection this event is about. The conn_handle you get from&amp;nbsp;&lt;span&gt;pm_conn_handle_get() is the conn_handle for the peer for which you have provided the peer_id. As this is a multi link project where you can be connceted to several peripherals at once, I do not quite understand why it is strange or an issue that you soemtimes get different conn_handle&amp;#39;s? I would think that both these are valid/authentic, just that they represent two separate connections. Is that not the case?&lt;/span&gt;&lt;/p&gt;
[quote user="Chaoyue Ying"]You mean I need to restart advertising when connection established and link encrypted so that I restart advertising at the enf of&amp;nbsp;PM_EVT_CONN_SEC_SUCCEEDED?[/quote]
&lt;p&gt;Not nesesarily. And I don&amp;#39;t have a full understanding of your application. But&amp;nbsp; you have a multi link application, which by nature, can have more than one connection (so more conn_handle&amp;#39;s can be valid at one time). So perhaps it would be easier to only scan and/or advertise during specific times when you are done with other tasks. There is no requierment to do this, though.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: peer_id,conn_handle and check connection</title><link>https://devzone.nordicsemi.com/thread/490446?ContentTypeID=1</link><pubDate>Tue, 25 Jun 2024 02:01:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c784252-d11a-4a69-91f0-653ebfea41a6</guid><dc:creator>Chaoyue Ying</dc:creator><description>&lt;p&gt;I get a screenshot share with you.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/1030._5563B783_.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;The conn_handle in first line is the value that p_evt-&amp;gt;conn_handle that is return from the p_context of the interrupt and the get handle in third line is the value that&amp;nbsp;get&amp;nbsp; by pm_conn_handle_get().&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure which one is authentic.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: peer_id,conn_handle and check connection</title><link>https://devzone.nordicsemi.com/thread/490437?ContentTypeID=1</link><pubDate>Tue, 25 Jun 2024 00:24:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:563a473e-ff4d-44e6-bc29-abd2bd185e65</guid><dc:creator>Chaoyue Ying</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You mean I need to restart advertising when connection established and link encrypted so that I restart advertising at the enf of&amp;nbsp;PM_EVT_CONN_SEC_SUCCEEDED?&lt;/p&gt;
&lt;p&gt;I use dev_find to find the save data to find the one of connection that a param equal to value to find a device(connection).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: peer_id,conn_handle and check connection</title><link>https://devzone.nordicsemi.com/thread/490333?ContentTypeID=1</link><pubDate>Mon, 24 Jun 2024 13:59:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e04dc01-4021-4710-9df6-3598e19903c3</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have not been able to digg down into the details of your code so I am not able to see what causes this issue. However, I wonder if you could make this a bit simpler for yourself by ensuring that you don&amp;#39;t start scanning again before the connection is properly established and the link encrypted)? That way, you will never have to deal with more than one &lt;em&gt;new&lt;/em&gt; connection at any time.&lt;/p&gt;
&lt;p&gt;PS: As a side note, I would suggest using defines to name the magic words used across this application to indicate states, as at least for me, it is difficult to understand what the&amp;nbsp;condition you use in your dev_find represents.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>