1. I had done the pairing without any authentication but now I want to do it with the authentication with an authentication key.
2. please provide some sample code regarding the pairing authentication and its process.
1. I had done the pairing without any authentication but now I want to do it with the authentication with an authentication key.
2. please provide some sample code regarding the pairing authentication and its process.
Hi,
Are you using NCS or nRF5SDK?
-Amanda
Hi team,
I am using the nRF52DK module PCA10040 board
Hi,
Sorry for the delay due to the weekend.
Since sending data from central/phone each time will trigger the nus_data_handler, I think you maybe could a global variable to count the failing input.
-Amanda
Hi amenda,
I had declare the local variable in the nus data handler
static void nus_data_handler(ble_nus_evt_t * p_evt)
{
int attempt = 0;
char arr[6];
char arr_1[6];
bool flag = 0;
if (p_evt->type == BLE_NUS_EVT_RX_DATA)
{
uint32_t err_code;
NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
{
do
{
err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
{
NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
APP_ERROR_CHECK(err_code);
}
}while (err_code == NRF_ERROR_BUSY);
}
if(p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
{
while (app_uart_put('\n') == NRF_ERROR_BUSY);
}
//storing the data into array which is comming from the ble_master(nrf_connect app)
for(int i=0; i<=5; i++)
{
arr[i] = p_evt->params.rx_data.p_data[i];
}
flag = 0;
// flag = 0; // password is correct
// flag = 1; // password is incorrect
if(flag == 0 && attempt == 0)
{
if(strcmp(arr, "123456") == 0)
{
printf("\nPassword is correct");
flag = 0;
}
if(strcmp(arr, "123456") != 0)
{
printf("\nPassword is incorrect!!! Please try again");
flag = 1;
attempt++;
}
}
if(flag == 1 && attempt == 1)
{
printf("\nPassword : "); // Here I want to wait till the new data had arrive
if(strcmp(arr, "123456") == 0)
{
printf("\nPassword is correct");
flag = 0;
}
}
// for n number of
}
}
I want to implemet the logic
1. 3 times password is wrong then I want to show "please reset the device"
You should try to run and debug by yourself. Please be aware that the risk might be as my colleague mentioned in this post.
-Amanda
Dear amenda,
Please let me know how to provide the wait state till the data aries.
Dear amenda,
Please let me know how to provide the wait state till the data aries.
Please see my colleague explained in this post.
-Amanda