Every time I try to connect to Android phone (running Android 7) or nrfConnect, it connects the first time. After I restart the nrf52 DK, the host takes a while to reconnect or does not connect at all, although its previously bonded. Restarting the board helps every time. What could be the issue in my firmware?
I tried changing the below parameters -
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(7.5/*100*/, UNIT_1_25_MS) /**< Minimum acceptable connection interval (0.1 seconds). */ #define MAX_CONN_INTERVAL MSEC_TO_UNITS(30/*200*/, UNIT_1_25_MS) /**< Maximum acceptable connection interval (0.2 second). */ #define SLAVE_LATENCY 0 /**< Slave latency. */ #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(100/*4000*/, UNIT_10_MS) /**< Connection supervisory timeout (4 seconds). */
I'm using SDK 15.2 with custom gatt & dfu services with uart peripheral.
I also tried adding
static void whitelist_set(pm_peer_id_list_skip_t skip) { pm_peer_id_t peer_ids[BLE_GAP_WHITELIST_ADDR_MAX_COUNT]; uint32_t peer_id_count = BLE_GAP_WHITELIST_ADDR_MAX_COUNT; ret_code_t err_code = pm_peer_id_list(peer_ids, &peer_id_count, PM_PEER_ID_INVALID, skip); APP_ERROR_CHECK(err_code); NRF_LOG_INFO("\tm_whitelist_peer_cnt %d, MAX_PEERS_WLIST %d", peer_id_count + 1, BLE_GAP_WHITELIST_ADDR_MAX_COUNT); //err_code = pm_whitelist_set(peer_ids, peer_id_count); err_code = pm_whitelist_set(NULL, 0); APP_ERROR_CHECK(err_code); }
static void advertising_start(bool erase_bonds) { if (erase_bonds == true) { delete_bonds(); // Advertising is started by PM_EVT_PEERS_DELETE_SUCCEEDED event. } else { whitelist_set(PM_PEER_ID_LIST_SKIP_NO_ID_ADDR); uint32_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); NRF_LOG_DEBUG("advertising is started"); } }
case PM_EVT_CONN_SEC_CONFIG_REQ: { // Reject pairing request from an already bonded peer. pm_conn_sec_config_t conn_sec_config = {.allow_repairing = true}; pm_conn_sec_config_reply(p_evt->conn_handle, &conn_sec_config); } break;
My advertising_init() -
static void advertising_init(void) { uint32_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 = true; init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; //init.advdata.uuids_complete.uuid_cnt = 1;//sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); //init.advdata.uuids_complete.p_uuids = m_adv_uuids; //init.advdata.uuids_complete.p_uuids = &m_adv_uuids[1]; /*new*/ init.config.ble_adv_whitelist_enabled = false;//true; /*BEBOP*/ init.srdata.name_type = BLE_ADVDATA_NO_NAME;//BLE_ADVDATA_NO_NAME; init.srdata.uuids_complete.uuid_cnt = 1;//sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); init.srdata.uuids_complete.p_uuids = &m_adv_uuids[0]; init.srdata.uuids_more_available.uuid_cnt = 1; init.srdata.uuids_more_available.p_uuids = &m_adv_uuids[1]; /*new*/ 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.config.ble_adv_extended_enabled = true; advertising_config_get(&init.config); 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); }