This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640R2F: How to connect a SimpleCentral based application to several Peripheral

Part Number: CC2640R2F

Hello

I have read several topics about multi connection from one Central to several Peripheral devices, but still have some questions about such a process for BLE5 stack.

I'm using "simplelink_cc2640r2_sdk_3_10_00_15" SDK and my application is based on "SimpleCentral" example program that I modified to have an autonomous connection to one peripheral with a specific name that was discovered.

At this step all is OK and works perfectly.

My next step is to connect my Central device up to 3 peripherals at the same time to send commands and data.

I can't find a good solution for that. 

Do someone can help me ?

Here is my progress and analyze :

- I start by calling "SimpleCentral_doDiscoverDevice()" which lists all the advertising Peripherals with the specific name I'm looking for (I don't use pairing and I dont want to use it)

- Then the main task receives SC_EVT_ADV_REPORT event which is processed by "ProcessAppMsg()"  for each discovered Peripheral

- "ProcessAppMsg()" then updates global variables 'numScanRes' and 'scanList[]' with discovered Peripheral datas

- An SC_EVT_SCAN_DISABLED event is then received and processeg by ProcessAppMsg() indicating that scannoing process has ended

- On this event received, ProcessAppMsg() calls "SimpleCentral_doConnect()" to initiate the connection on the found Peripheral (infact, it calls the "GapInit_connect()" function from BLE5-Stack).

I tried to modify at this step by adding a loop to ask for all discovered Peripheral listed in 'scanList[]' but it seems that I only receive one time the next event which is GAP_LINK_ESTABLISHED_EVENT, processed by "ProcessGapMsg()". From my analyze and understanding, It is supposed to update the global variables 'connList[]' an 'numConn', but this is not the situation I observe. 

Could someone help me and told me what is the best way to do into this project ?

THank you in advance for any help.

Best regards.Patrick

  • Bonjour Patrick :)

    First of all,  have you modified the max number of BLE connections allowed? This must be done in the file ble5_simple_central_cc2640r2lp_app_FlashROM_StackLibrary.opt by modifying the value of MAX_NUM_BLE_CONNS (by default the max number of BLE connections is 2)

    From my understanding, you are executing the function GapInit_connect() without waiting for the GAP_LINK_ESTABLISHED_EVENT. This should be avoided. By the way, I would advice you to check the value of the status returned by the function GapInit_connect() (you can have a look to the documentation here)... I am pretty sure you receive a status bleNotReady if you don't wait for GAP_LINK_ESTABLISHED_EVENT between two calls to GapInit_connect().

    I hope this will help,

    Kind regards,

  • Hello Clément,

    Are you French ?!

    So, for the first question, my answer is yes, I changed the MAX_NUM_BLE_CONNS up to 3 (this is the max number of devices I want to allow).

    Then, I checked the status returned by GapInit_connect() : it indicates that it's already performing that task (bleAlreadyInRequestedMode 0x11 is returned).

    So, I tried to add a TaskSleep in my connect loop. The idea was to free CPU time for the task to catch and process the GAP_LINK_ESTABLISHED_EVENT. It is not able to connect to my 3 peripheral at the same time (with the TaskSleep delay between each). This is probably not the best way to do but it confirm that this is the reason at this step.

    But, I'm still blocked at the next step : In SimpleCentral example program (which is the template program I used for my application), when GAP_LINK_ESTABLISHED_EVENT is received, there is a call to a "SimpleCentral_doSelectConn()" function, for one of the established connections, which send an internal SC_EVT_SVC_DISC event to the main "ProcessAppMsg()" function. On this event received, a "SimpleCentral_startSvcDiscovery()" is then called, which performs a GATT_ExchangeMTU event, starting the Service discovery for this connection. 

    If I select one of the 3 established connections, Service discovering is OK and I can write in my Peripheral Characteristics.

    But I don't know how to proceed at this step to have both my 3 connexions selected and Service discvovered on each of them simultaneously.

    Is it possible ?

    From your experience, what should be the best way to proceed ?

    THank's again!

    Patrick

     

  • Just use multi role example program to connect to up to 3 peripheral.

    -kel

  • Hello

    Yes, I already looked into this example program, but I couldn't do exactly what I want :

    In fact, I need to connect and exchange data with several peripherals simultaneously. From what I could understand in the multirole example, the device discovering allow to discover all of them, but the connection and service discovery is made one by one.

    Is that the only way to do, or is it possible to discover all devices, then select all my 3 connections and have all of them openned to write in parallel in the discovered characteristics of each ?

    THanks

  • Patrick COMBETTE said:
    From what I could understand in the multirole example, the device discovering allow to discover all of them, but the connection and service discovery is made one by one.

    Once the 3 peripherals pair to the multi role, you can set it to reconnect using the menu, from what I remember. So next connection the 3 peripherals will connect simultaneously.

    Just a caution with connection multiple peripherals to multi role, it requires memory. If you have memory problems at multi role side you will experience disconnection.

    Maybe you can do this the ibeacon or eddystone beacon way.

    -kel

  • Hi Patrick,

    Yes, I am French :)

    Can you tell us if the solution offered by could help you?

    Kind regards,

  • HEllo,

    In fact, the solution you proposed, didn't fully help me, but a little bit !

    I could modify the SimpleCentral example to discover and connect to all my Peripherals, but I'm still not able to Select all connections and write to each of them.

    As you mentionned, I encountered a memory size issue and was obliged to reduce Stack sizes to prevent this (I had intempestive disconnections). This side is solved now.

    I observed that in the SimpleCentral example program, the way used to select a connection and permform read and write operations in characteristics on a discovered and connected device, is based on a "doSelectConn()" function which itself starts the ServiceDiscovery. But these functions use a common 'scConnHandle' variable pointing to the connection and used for all subsequent functions.

    I think I need to change this....

    ANyway, I'm not sure of the best way to program this algorithm...

    I hou have any idea or suggestions, you're welcome !

    If you need I can post my modified code for SimpleCentral, just let me know.

    THanks again !

    Patrick

  • Hi !

    Ok, so we could speek Frenche, but for other people It's better to conitinue in English !

    You can see the reply I sent to Markel,

    In fact I have progressed a little bit but still have problems to select all established connections and start Service discovery sucessively on each of them, automatically (without button menu).

    THank's for help.

    Bonne soirée !

    Patrick

  • Hi Patrick,

    So your problem is to write data to all your connections at the same time. Right?

    If you have a look to your BLE projects, you will find the file named simple_gatt_profile.c (this file is generally in the folder PROFILES). This is here that all the data shared in the BLE connections are. In general the data are stored in the table simpleProfileAttrTbl[] and the function GATTServApp_RegisterService() is used to register the services added. At the same time as the services, you register a set of callbacks (their type is gattServiceCBs_t).

    EDIT: I missed a part of your questions :)

    If your problem is while performing discovery, then the multi_role example presents the way to allocate memory (using ICall_malloc) and to read/write the content of discInfo[].

    I hope this will help,

    Kind regards,

  • Hello Clement,


    At first I wish you a very happy ney year.

    I just restart my project after some holiday !

    So, I confirm that my propblem is to write data to all my connected devices. I successed to discover devices (peripherals), to connect them, but still not found a way to write them at the same time (or with a little time delay).

    Regarding to my initial post about this topic, 2 of the 3 steps are now OK in the processing :

     _doDiscoverDevice()

    _doConnect()

     

     

    The next step I don't know how to manage is the _doSelectConn() : I can choose one connection in the list (connList[] variable), then select it, start service discovery, and finally write to the wanted  characteristic. But I don't understand how to do this simulaneously or sequentially but small delay between each. The limitation is due to the fact that there is only one global variable used to record the selected connection ('scConnHandle' ). What would you recomment to do that ?

    Best regards

    PAtrick

  • Hi Patrick,

    Glad to have you back. Happy new year to you too!

    If you problem is having only one connection handle, then why are you not declaring one or two more? You can have a look to the way multi_role example is handling the variable connHandleMap. You will see that a memory allocation is done using ICall_malloc() and a function (multi_role_mapConnHandleToIndex) has been written to find to which connection a given connection handler is belonging.

    I hope this will help,

    Regards,

  • Hi Clement,

    Ok, that's what I want to do on a general way !

    I understand how to do now, and I will code this way in my application program.

    THank's for all,

    Patrick