Multiple connections for CS

Hi,

I am currently working on making it possible to connect with different devices sequentially. It was told to me that it is possible to first scan all devices, and then connect to them one by one. I am currently working on that and i made it possible to store all the connections in my connections array. This is what i get:



So we get behind the semaphores of the SCANNING and hus behind the LOG_INF of the MAIN():



I thought it was possible to then just use a for loop and the reconnect to the devices one by one, but maybe i am missing something. 

Can someone help me with this please?

Kind Regards,

Nick De Leenheer

Parents
  • Hello,

    When you're done with a connection, you should:
    Call bt_conn_disconnect() with an appropriate reason code (like BT_HCI_ERR_REMOTE_USER_TERM_CONN)
    Call bt_conn_unref() to release your reference to the connection object

    It's important to understand that connection objects are reference counted. As explained in this DevZone thread:
    "Connection objects are reference counted, and the application is expected to use the bt_conn_ref() API whenever storing a connection pointer for a longer period of time, since this ensures that the object remains valid (even if the connection would get disconnected). Similarly the bt_conn_unref() API is to be used when releasing a reference to a connection."

    I expect in this case that you are not using bt_conn_ref() and bt_conn_unref() for each connections.

    Kenneth

  • Hi,

    Thank you very much for this. Currently i have this and it works:

    So now i got all the addresses stored in an array, all the connection pointers, and all the reflector names. I now use the addresses for bt_le_conn_create()... But someone told me that i can store connection parameters in CACHE. I dont really understand how to to this storring though.

    But when reading your respons, is it possible for me to just use bt_conn_ref() to reconnect again with the device then? Because you say that it stores a connection pointer for a longer amount of time? And does this means then that i don't have to create new connections every time?

    Kind regards,

    Nick De Leenheer

Reply
  • Hi,

    Thank you very much for this. Currently i have this and it works:

    So now i got all the addresses stored in an array, all the connection pointers, and all the reflector names. I now use the addresses for bt_le_conn_create()... But someone told me that i can store connection parameters in CACHE. I dont really understand how to to this storring though.

    But when reading your respons, is it possible for me to just use bt_conn_ref() to reconnect again with the device then? Because you say that it stores a connection pointer for a longer amount of time? And does this means then that i don't have to create new connections every time?

    Kind regards,

    Nick De Leenheer

Children
  • NickDeLeenheer said:
    is it possible for me to just use bt_conn_ref() to reconnect again with the device then?

    No, you cannot use bt_conn_ref() to reconnect to a previously connected device. You can store the device address after the first discovery and reuse it, but you must recreate the connection — bt_conn_ref() is only for managing references to an active connection.

    Kenneth

  • Hi Kenneth,

    Thank you very much! I now have working Semaphores and working chronology:

    With a for loop of MAX_RANGING_ROUNDS for the ranging process:



    And this is the outputs that works Succesfully until the security step for the next device:


    I don't know why this is. I use a conn* pointer for every connection = NULL. Why should this work for the first device but not for the second?

    I have also tried to use bt_conn_disconnect after the end of the ranging process, but this gives me this weird ASSERTION ERROR and REBUILD sequence constantly:



    Can you help me with this?

    Kind regards,

    Nick De Leenheer




Related