peer_id,conn_handle and check connection

I'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 and conn_handle about a new security connection at pm_evt_handler that are contained in pm_evt_t that be called back.

Maybe due to the quickly connect and disconnect,sometimes the conn_handle that I saved is not equal to the one that get from pm_conn_handle_get().

And it seem either the save one or the get one be used in ble_nus_data_send() seem also can return NRF_SUCCESS but the data is not send to the aim.

So I try to poll the save conn_handle and the get conn_handle,if they are not equaled,I will try to disconnect the connection so that they can try to connect again.

But it seem inoperative.

I want to get the way to solve it.And the code as follow.

1202蓝牙程序v0.1.8.rar

  • Hi,

    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'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 new connection at any time.

    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 condition you use in your dev_find represents. 

  • Hi,

    You mean I need to restart advertising when connection established and link encrypted so that I restart advertising at the enf of PM_EVT_CONN_SEC_SUCCEEDED?

    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).

  • I get a screenshot share with you.

    The conn_handle in first line is the value that p_evt->conn_handle that is return from the p_context of the interrupt and the get handle in third line is the value that get  by pm_conn_handle_get().

    I'm not sure which one is authentic.

  • Hi,

    Chaoyue Ying said:

    The conn_handle in first line is the value that p_evt->conn_handle that is return from the p_context of the interrupt and the get handle in third line is the value that get  by pm_conn_handle_get().

    I'm not sure which one is authentic.

    The conn_handle you get in p_evt->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 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's? I would think that both these are valid/authentic, just that they represent two separate connections. Is that not the case?

    Chaoyue Ying said:
    You mean I need to restart advertising when connection established and link encrypted so that I restart advertising at the enf of PM_EVT_CONN_SEC_SUCCEEDED?

    Not nesesarily. And I don't have a full understanding of your application. But  you have a multi link application, which by nature, can have more than one connection (so more conn_handle'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.

  • Hi,

    Maybe I not make myself clear,I mean the p_evt->conn_handle and the conn_hanle that get from pm_conn_hanle_get() should point to the same device.

    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 ble_nus_data_send()?

    In my impression,neither p_evt->conn_handle or pm_conn_handle_get() used in ble_nus_data_send() return NRF_SUCCESS but both no data recived in the peer device.

Related