Hi I want to get the peripheral address from the UART and compare with scanned peripheral addresses from the central (nrf52832) and if the received address string is of one of the scanned devices list, the central will connect to that particular device. Actually it's like "connect <device address>" in "ble_app_interactive" (SDK15.2.0) but from the UART instead of CLI. But I don't know how to do this.
I use ble_app_uart_c as a central and scan for the peripheral of NUS type and I found. Now I want to connect one of the scanned NUS peripheral devices which address is from the UART. When I studied "cmd_device_connect()" function in ble_app_interactive example, I couldn't find how they retreive the address from the string, compare and connect.
How can I do this? Thanks
/**@brief Command handler for establishing a connection.
*/
static void cmd_device_connect(nrf_cli_t const * p_cli, size_t argc, char ** argv)
{
if ((argc == 1) || nrf_cli_help_requested(p_cli))
{
nrf_cli_help_print(p_cli, NULL, 0);
return;
}
if (argc == 2)
{
//Connect by peer ID if davice was bonded and using privacy.
if (strlen(argv[1]) < (ADDR_STRING_LEN - 1))
{
uint16_t pm_id;
pm_id = atoi(argv[1]);
private_connect(&pm_id);
return;
}
// If address or peer ID have incorrect format, then return.
if (strlen(argv[1]) != (ADDR_STRING_LEN - 1))
{
nrf_cli_fprintf(p_cli,
NRF_CLI_ERROR,
"wrong address length - Correct format: XX:XX:XX:XX:XX:XX\r\n");
return;
}
//Connect by device address.
addr_store_value_set(argv[1]);
}
else
{
nrf_cli_fprintf(p_cli, NRF_CLI_ERROR, WRONG_PARAMETER_COUNT);
}
}