Hello,
I am trying on purpose to connect to an address which does not exist:
bd_address_t peer_addr = {
.addr_type=PUBLIC_ADDRESS,
.addr={0x21, 0x21, 0x21, 0x21, 0x21, 0x21}
};
ble_gap_connect(&peer_addr, &conn_params);
Since the connection should fail (there is no device with this address), I expect to get a connection failure event, like the documentation of ble_gap_connect() says:
This call initiates a direct connection procedure to a specified device. The application will get [...] a ::BLE_EVT_GAP_CONNECTION_COMPLETED event when the connection procedure is completed either successfully or with error.
My problem is that I do not get this event (or any event at all) following this ble_gap_connect() call. However I get the BLE_EVT_GAP_CONNECTION_COMPLETED event on successful connections.
Hi apoudret,
Can you please configure it with a private BD address and check if you are able to get the BLE_EVT_GAP_CONNECTION_COMPLETED event whenever a connection is completed successfully or unsuccessfully? If you are still unable to get this event, can you please let me know which error are you getting in the unsuccessful connections?
Thanks, PM_Dialog
Hello PM_Dialog,
My initial test was with public addresses.
I just tried using a device with a private address, and I get the same behavior:
- if address is valid, ble_gap_connect() returns BLE_STATUS_OK and I get the GAP_CONNECTION_COMPLETED event
- if address is invalid, ble_gap_connect() still returns OK BLE_STATUS_OK but I do not get the GAP_CONNECTION_COMPLETED event
By the way I just noticed something:
- My peripheral device was off. I tried to connect to the peripheral device with my central device. I called ble_gap_connect() but I got no event.
- I powered on my peripheral device after 30 seconds. I got the connection successful event on my central device.
This means that during the whole 30 seconds the central device was trying to connect: it did not timeout.
Hi apoudret,
The 30seconds are according to BLE specifications, and within this time the device is trying to connect with a peripheral. Could you please clarify if you are still unable to get the BLE_EVT_GAP_CONNECTION_COMPLETED event?
Thanks, PM_Dialog
Hello PM_Dialog,
Your answer seems inaccurate: if I wait for 5 minutes to turn on the peripheral device (instead of 30 seconds), the central device still manages to connect once the peripheral is turned on.
你能指出我的祝福speci吗fication which specifies those 30 seconds?
I am still unable to get the BLE_EVT_GAP_CONNECTION_COMPLETED event. The ble_gap_connect() never times out.
Best regards,
Andy
Hi apoudret,
My apologies, but I didn’t understand what you mentioned with the 30seconds. I thought that you were waiting 30 seconds until the connection, and not that you turn on the peripheral after 30 seconds. In general, according to BLE specifications, the maximum timeout is 30 seconds, but in your case, I am not aware in which level the time out is happened. Regarding the fact that you are not able to get the BLE_EVT_GAP_CONNECTION_COMPLETED event, first you have to get the BLE_EVT_GAP_CONNECTED and then you will get the BLE_EVT_GAP_CONNECTION_COMPLETED if the connection procedure is completed either successfully or unsuccessfully. So, if you are trying to connect to an invalid BD address, you will never get the BLE_EVT_GAP_CONNECTION_COMPLETED as long as you have never received the BLE_EVT_GAP_CONNECTED.
Thanks, PM_Dialog
Hello PM_Dialog,
You say that "if you are trying to connect to an invalid BD address, you will never get the BLE_EVT_GAP_CONNECTION_COMPLETED as long as you have never received the BLE_EVT_GAP_CONNECTED".
However if you look at the documentation of the ble_gap_connect() method, it says:
"The application will get [...] a ::BLE_EVT_GAP_CONNECTION_COMPLETED event when the connection procedure is completed either successfullyor with error (in the second case, ::BLE_EVT_GAP_CONNECTED will not be received)."
Since I am trying to connect to an invalid BD address, I should get a GAP_CONNECTION_COMPLETED when the connection procedure should fails.
你说“根据BLE规范,maximum timeout is 30 seconds".
If this is true, it means that your SDK does not follow the BLE specs since I do not get any timeout even after 5 minutes.
Best regards,
Andy
Hi apoudret,
While you are trying to connect to a peripheral with an invalid BD address, the scan procedure will not stop, so you will not get either BLE_EVT_GAP_CONNECTED or BLE_EVT_GAP_CONNECTION_COMPLETED event. If you call explicitly the ble_gap_connect_cancel(), then the scan procedure will stop and you will get the BLE_EVT_GAP_CONNECTION_COMPLETED event with error status 0x12 (terminated by the user). If you don’t stop the scanning procedure explicitly, the central device will continue scanning and you will not get any event. Probably the comments of the ble_gap_connect() function are little bit misleading.
Thanks, PM_Dialog
Hello PM_Dialog,
Thank you for your answer. I will start a task which will call ble_gap_connect_cancel() after X seconds.
Andy