Dear Sir,
I wanted to make the peripheral connect to a predefined central device. Here I am using an android phone ( with nRFConnect installed in it) as the central device.
I was using ble_app_hrs code as reference and modified as follows to implement the whitelist operation.
I want the peripheral to be visible/connect to only those device whose address is mentioned in the whitelist.
I have made the following changes in the 'ble_app_hrs' code.
Inside function "advertising_init()" the following line is added
init.config.ble_adv_whitelist_enabled = true;
And the line
init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
is changed as follows
init.advdata.flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;//BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
Then insdie function "on_adv_evt(ble_adv_evt_t ble_adv_evt)" the following lines are added on top
ble_gap_addr_t peer_addr; //peer device address ble_gap_addr_t const * p_peer_addr;
And inside the same function in 'switch (ble_adv_evt)' added the following case also
case BLE_ADV_EVT_WHITELIST_REQUEST: memset(&peer_addr, 0x00, sizeof(peer_addr)); peer_addr.addr[5] = 0xdc;//EC; peer_addr.addr[4] = 0x15;//9F; peer_addr.addr[3] = 0x33;//A1; peer_addr.addr[2] = 0x01;//E5; peer_addr.addr[1] = 0x41;//5B; peer_addr.addr[0] = 0xbc;//B3; peer_addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC; // Add the address type p_peer_addr = &peer_addr; // Set white list err_code = sd_ble_gap_whitelist_set(&p_peer_addr, 0x01); //swap pp_peer_addr with &p_peer_addr, like this if (err_code == NRF_SUCCESS) { NRF_LOG_INFO("Successfully set whitelist!\n"); } APP_ERROR_CHECK(err_code); //Added an error check, always useful to have. // White list reply err_code = ble_advertising_whitelist_reply(&m_advertising,p_peer_addr, 1, NULL, (uint32_t) NULL); if (err_code == NRF_SUCCESS) { NRF_LOG_INFO( "Whitelist replied\n"); } APP_ERROR_CHECK(err_code); break;
Now I flashed the program to a peripheral device.
I have tried to connect to the peripheral in two ways
1) Using nRFConnect Desktop App with the help of another BLE DK from Rigado- In this case I could see the peripheral name in the App and I could establish the connection successfully.
2)Using ANdroid phone( with nRFConnect App installed in it) - In this case I had to give the address in reverse order and I could see the peripheral device while scanning .But here when I try to connect to the peripheral it fails with the following message( shown in the App in phone)
The following image shows the address in my mobile phone
Is there anything to do with the address type.?
Or anything else I am missing ?
Please shre your comments .
with regards,
Geetha