Hi
I need to connect to perticular central and i know the central MAC address. So i am using whitelisting in peripheral.
I made below changes in my code in ble_app_uart but central getting connected disconnected so fast. Did i miss something to add in code or whats the problem?
1. When i used peer_addr.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC; then peripheral is seen on nrf but not able to connect and when i set BLE_GAP_ADDR_TYPE_RANDOM_STATIC no peripheral is shown on nrf app.
static void on_adv_evt(ble_adv_evt_t ble_adv_evt) { uint32_t err_code; ble_gap_addr_t peer_addr; //peer device address ble_gap_addr_t const * p_peer_addr; switch (ble_adv_evt) { case BLE_ADV_EVT_FAST: err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING); APP_ERROR_CHECK(err_code); break; case BLE_ADV_EVT_IDLE: sleep_mode_enter(); break; case BLE_ADV_EVT_WHITELIST_REQUEST: memset(&peer_addr, 0x01, sizeof(peer_addr)); ////peer_addr.addr[0] = 0xbc; | Reverse the order you placed these: ////peer_addr.addr[1] = 0x41; | ////peer_addr.addr[2] = 0x01; | Also note that you used wrong address, ////peer_addr.addr[3] = 0x31; | as I said in my reply ////peer_addr.addr[4] = 0x8f; | ////peer_addr.addr[5] = 0x48; | Insert the address like this: peer_addr.addr[5] = 0x41; peer_addr.addr[4] = 0x4D; peer_addr.addr[3] = 0x9E; peer_addr.addr[2] = 0xF8; peer_addr.addr[1] = 0x50; peer_addr.addr[0] = 0xE1; //// c1a7f5c23cc6 peer_addr.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC; // Add the address type ////peer_addr pointers. Double pointers for the win! :S p_peer_addr = &peer_addr; ////pp_peer_addr = &p_peer_addr; --> Remove this line //// 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) { printf("Successfully set whitelist!\r\n"); } else { printf("Whitelist not set\r\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) { printf( "Whitelist replied\r\n"); } else { printf("Whitelist not replied\r\n"); } APP_ERROR_CHECK(err_code); break; default: break; } } static void advertising_init(void) { ret_code_t err_code; ble_advertising_init_t init; memset(&init, 0, sizeof(init)); init.advdata.name_type = BLE_ADVDATA_FULL_NAME; init.advdata.include_appearance = false; init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; // Comment this line out if you havn't done it already init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); init.advdata.uuids_complete.p_uuids = m_adv_uuids; init.config.ble_adv_fast_enabled = true; init.config.ble_adv_fast_interval = APP_ADV_INTERVAL; init.config.ble_adv_fast_timeout = APP_ADV_DURATION; init.advdata.flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; // These two lines are correct init.config.ble_adv_whitelist_enabled = true; // init.evt_handler = on_adv_evt; err_code = ble_advertising_init(&m_advertising, &init); APP_ERROR_CHECK(err_code); ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG); }
Please suggest how to connect one peripheral to particular central?