Hello everyone,
Right now I am working on a demo showing some functionalities of 2 smartwatches: Colmi P8B and PineTime. I am using nRF52840 for that purpose.
I had the idea the following idea:
- When BSP_EVENT_KEY_1 is pressed, a name filter is set for one of the smartwatches (Colmi) and a new scan with that parameter is launched. This part is working fine and a connection with the smartwatch I'm looking for is happening.
- When BSP_EVENT_KEY_3 is pressed, the previously started connection is broken as I trigger a disconnection event. This part is also working fine.
- When BSP_EVENT_KEY_2 is pressed, another name filter is set, now for the other smartwatch (PiniTime) and a new scan with that parameter is launched.
Here is the problem: Sometimes I am able to connect to the smartwatch (PineTime) I'm requesting when pressing BSP_EVENT_KEY_2 ; however, most of the times the connection is re-established with the other smartwatch.
Following is the code of the implementation of the part of the buttons.
void bsp_event_handler(bsp_event_t event)
{
ret_code_t err_code;
char m_target_periph_name_1[] = "InfiniTime";
char m_target_periph_name_2[] = "P8b";
switch (event)
{
case BSP_EVENT_SLEEP:
nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);
break;
case BSP_EVENT_DISCONNECT:
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
if (err_code != NRF_ERROR_INVALID_STATE)
{
APP_ERROR_CHECK(err_code);
}
break;
case BSP_EVENT_WHITELIST_OFF:
whitelist_disable();
break;
case BSP_EVENT_KEY_1:
err_code = nrf_ble_scan_filter_set(&m_scan,
SCAN_NAME_FILTER,
m_target_periph_name_2);
NRF_LOG_INFO("Scanning for COLMI PB8 Smartwatch");
scan_start();
APP_ERROR_CHECK(err_code);
break;
case BSP_EVENT_KEY_2:
err_code = nrf_ble_scan_filter_set(&m_scan,
SCAN_NAME_FILTER,
m_target_periph_name_1);
NRF_LOG_INFO("Scanning for Pinetime Smartwatch");
scan_start();
APP_ERROR_CHECK(err_code);
break;
case BSP_EVENT_KEY_3:
err_code =sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
if (err_code != NRF_ERROR_INVALID_STATE)
{
APP_ERROR_CHECK(err_code);
}
NRF_LOG_INFO("Disconnected from smartwatch. ");
break;
default:
break;
}
}Any suggestions are welcome
Thanks in advance!
PS: I can´t just turn off one of the smartwatches so it stops advertising.