Dear all,
Hi,
I want to connect with two peripherals from a central simultaneously. I can connect to one of the peripherals and at the same time scan for other module. However, after detecting the other one I can't connect to that. Any advice is appreciated.
Thanks you
Device:
No body has any idea!?
Hi, maybe the BD address should not be all the same.
Thank you, I use different BD addresses, but still I can't connect to two peripherals simultaneously. I must disconnect from one to connect to the other one.
As Dialog says, I can connect to 6 peripherals at the same time. However, I am unable to connect to even two of them.
Can anybody help? should I change any parameter when want to send a start_connection command?
The parameters I set for the start connection command is as follows:
msg->nb_peers = 5;
memcpy(&msg->peers[0].addr, &connect_bdaddr[device_num], BD_ADDR_LEN);
msg->con_intv_min = 10;
msg->con_intv_max = 10;
msg->ce_len_min = 32;
msg->ce_len_max = 32;
msg->con_latency = 0;
msg->op.addr_src = GAPM_PUBLIC_ADDR;
msg->peers[0].addr_type = GAPM_PUBLIC_ADDR;
msg->superv_to = 100;
msg->scan_interval = 384;
msg->scan_window = 352;
msg->op.code = GAPM_CONNECTION_DIRECT;
Dialog,
Hi,
Could you please give me some advice?
Is there any sample code you may kindly forward to me?
My email isreza.yazdani1367@gmail.com.
Thank you
nb_peers should be set to 1 (not 5) for direct connection. Are you sure you are allocating the message object correctly with the correct size?
You also have to change a #define in da14580_config.h with the maximum number of simultaneous peripherals you want to support.
Thanks Joacimwe.
I changed number of peers (nb_peers) based on some advice from a person in dialog staff (named RvA) that I saw in the following link:
http://support.dialog-semiconductor.com/connection-multiple-peripherals
The message allocation I used is like what is used in dsps application:
msg = (struct gapm_start_connection_cmd *) KE_MSG_ALLOC(GAPM_START_CONNECTION_CMD , TASK_GAPM, TASK_APP, gapm_start_connection_cmd);
Is it enough that I increase the number of simultaneous peripherals (BLE_CONNECTION_MAX_USER) in da14580_config.h!? Or should I change other parameters too!?
I will do the changes you mentioned and let you know of the result soon. I really appreciate your help, thank you.
I did all the changes I think is needed to have two peripherals connected to one central simultaneously. I also used UM-B-011 DA14580 MemoryMapTool to correct the memory map in da14580_config.h. But nothing works out! I don't know what else I should do.
Is it right that I should connect to all the peripherals one by one!?
Can somebody help?
Dialog, can you give me any advice on this, please?
Messages with variable length (in this case the number of peers) must be allocated with KE_MSG_ALLOC_DYN like this:
KE_MSG_ALLOC_DYN(GAPM_START_CONNECTION_CMD , TASK_GAPM, TASK_APP, gapm_start_connection_cmd, nb_peers * sizeof(struct gap_bdaddr)) where nb_peers should be the same number you put into msg->nb_peers.
As stated inhttp://support.dialog-semiconductor.com/resource/gap-interface-specifica...1、nb_peers GAPM_CONNECTION_DIRECT。
If you do this together with setting BLE_CONNECTION_MAX_USER, that should be enough. Just make sure you initiate a direct connect two times, first for the first peripheral (with its mac address put into msg->gap_bdaddr[0]), and then to the second peripheral (with its mac address put into msg->gap_bdaddr[0]). Note that you must wait until the first one has connected until you can start the connection of the second one. (Wait until GAPM_CMP_EVT). Other BLE chips support multiple simultaneous pending connections, but the DA14580 doesn't seem to do that. Instead you can scan for multiple peripherals and initiate a direct connection as soon as one of interest appears (but then you might want to have a timeout for this direct connection and go back to scan if you can't connect in say 30 seconds).
Thanks for your help.
At last, I connected two modules to a central.
I think the problem was that I didn't wait until a connection is completed and started next connection after receiving GAPC_CONNECTION_REQ_IN. However, as you said, I should start next connection after receiving GAPM_CMP_EVT. I really appreciate your advice.
I also have another question about the time that I must wait until BLE central can connect to the second peripheral module. As I have tested several times, I couldn't measure a predictable timing. So, I am concerned how I can set this timing. If I am connecting to two modules from a central, should I define two separate profiles handling each of them!?
I appreciate your consideration in advance.
You should be able to immediately connect to the second peripheral once you receive GAPM_CMP_EVT (with the operation parameter set to GAPM_CONNECTION_DIRECT) so you don't have to add some delay before you connect to the next peripheral. The GAPM_CMP_EVT message is normally sent immediately after GAPC_CONNECTION_REQ_IND.
Note that the "state" of the TASK_APP as it is done in the template project (idle, advertising, connected, ...) doesn't really make sense when you have multiple peripherals in central mode. You should instead keep track somehow for each peripheral that is connected in some other way.
Thanks for the advice.
I am doing just as you said, but I can't connect to the second device immediately after connecting to the first one.
I thought that it might be because of enabling sps profile and receiving notification events from the first connected device that I can't have second connection instantly. So, I changed the program in a way that the profile is enabled after second connection. However, I can't connect to the second device without an UNPREDICTABLE delay!!!
Do you have any idea how I can reduce the delay or at least have a predictable delay!?
I haven't seen this before. I can connect directly to the second one after GAPM_CMP_EVT...
What happens instead? Are you getting an GAPM_CMP_EVT with a non-zero status code or does nothing happen at all?
Can you see using Smart Snippets current measurement to see what's happening?
Try to increase your connection interval and reduce the scan window/interval so the da14580 is not busy with connection events of the first peripheral while it scans for the second one.
Thanks, I will check this solution too.
I think nothing happens at all because I use a serial monitoring program to see when and why the app is going to the handler of GAPM_CMP_EVT. However I will check that again to see if I am missing something or not!
I really appreciate your help.
Finally, I found what is problem that I can't connect to the second device right after connecting to the first one.
It is just about some parameters that was set in the app_connect function! If I change the parameter setting as follows and leave the other parameters to be set to their default value, all the things work correctly and no unpredictable delay happens at all!
msg = (struct gapm_start_connection_cmd *) KE_MSG_ALLOC_DYN(GAPM_START_CONNECTION_CMD , TASK_GAPM, TASK_APP,
gapm_start_connection_cmd, sizeof(struct gap_bdaddr));
msg->nb_peers = 1;
memcpy(&msg->peers[0].addr, connect_bdaddr[index].addr, BD_ADDR_LEN);
msg->con_intv_min = APP_CON_INTV_MIN;
msg->con_intv_max = APP_CON_INTV_MAX;
msg->op.addr_src = GAPM_PUBLIC_ADDR;
msg->peers[0].addr_type = GAPM_PUBLIC_ADDR;
msg->superv_to = APP_CON_SUPERV_TO;
msg->scan_interval = APP_CON_SCAN_INTERVAL;
msg->scan_window = APP_CON_SCAN_WINDOW;
msg->op.code = GAPM_CONNECTION_DIRECT;