What is the lifespan of the connection object struct bt_conn?

A peripheral advertises to a central and a connection is established as the peripheral's callback function is executed with parameter struct bt_conn *conn.

  • Will this particular connection object remain the same through disconnects and reconnections of the central?
  • Can I save the address of this object as an identifier of this particular connection and compare it with the conn parameter passed to connect and disconnect callbacks?
  • What impact does a call to bt_conn_ref() or bt_conn_unref() have on how this works?

Thanks,

Ken

Parents
  • Hi,

    Will this particular connection object remain the same through disconnects and reconnections of the central?
    What impact does a call to bt_conn_ref() or bt_conn_unref() have on how this works?

    The connection object is valid as long as you called bt_conn_ref() and until bt_conn_unref() is called, even if the connection is terminated before. See Connection management. It cannot be used for much after the connection is temrinated though, but the information will still be valid.

    Can I save the address of this object as an identifier of this particular connection and compare it with the conn parameter passed to connect and disconnect callbacks?

    You can store the peer address and compare with the address in future connections. However, in some cases the same devicmay connect with a different address if using privacy (random resolvable address), which for instance all modern phones do.

    If you want to keep track of a device, it often makes sense to bond with it. If it use privacy, the IRK (identity resolution key) is exchagned so that you can identify it even as the address change.

Reply
  • Hi,

    Will this particular connection object remain the same through disconnects and reconnections of the central?
    What impact does a call to bt_conn_ref() or bt_conn_unref() have on how this works?

    The connection object is valid as long as you called bt_conn_ref() and until bt_conn_unref() is called, even if the connection is terminated before. See Connection management. It cannot be used for much after the connection is temrinated though, but the information will still be valid.

    Can I save the address of this object as an identifier of this particular connection and compare it with the conn parameter passed to connect and disconnect callbacks?

    You can store the peer address and compare with the address in future connections. However, in some cases the same devicmay connect with a different address if using privacy (random resolvable address), which for instance all modern phones do.

    If you want to keep track of a device, it often makes sense to bond with it. If it use privacy, the IRK (identity resolution key) is exchagned so that you can identify it even as the address change.

Children
Related