This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Reconnecting issue

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 -

Fullscreen
1
2
3
4
#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). */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I'm using SDK 15.2 with custom gatt & dfu services with uart peripheral.

I also tried adding

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
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);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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");
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Fullscreen
1
2
3
4
5
6
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;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

My advertising_init() -

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Parents
  • Hi. 

    From the code you uploaded, I can't see why you don't receive the disconnect event. You should see the disconnected event when you disconnect using your phone. 

    Are you using an application for connecting/disconnecting, or are you using the native bluetooth settings on the phone to connect/disconnect?

    If you aren't seeing the disconnection event, you could try to reduce the connection timeout and see if you would get the timeout/disconnect event after the timeout expires.

    Best regards,
    Joakim

  • The below sequence happens once in 10 attempts - 

    1. Host bonds with device or reconnects to already bonded device

    2. Host requests MTU size of 32 - success

    3. Host enables notifications

    4. Host receives 23 byte packets, instead of 32.

    5. Host displays error message - device not found, out of range.

    How can I restrict sending 23 bytes instead of 32 bytes in the firmware before MTU request is accepted?

Reply
  • The below sequence happens once in 10 attempts - 

    1. Host bonds with device or reconnects to already bonded device

    2. Host requests MTU size of 32 - success

    3. Host enables notifications

    4. Host receives 23 byte packets, instead of 32.

    5. Host displays error message - device not found, out of range.

    How can I restrict sending 23 bytes instead of 32 bytes in the firmware before MTU request is accepted?

Children