BLE not connecting after disconnect

I have a problem with connecting to my device after i disconnect from it.

I have tried ubond function, it does not work.

This is my disconnect function:

/*
	@brief callback function when BT connection is disconnected
*/
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF("Disconnected: %s, reason 0x%02x %s", addr, reason, bt_hci_err_to_str(reason));

	if (auth_conn) {
		bt_conn_unref(auth_conn);
		auth_conn = NULL;
	}

	if (current_conn) {
		bt_conn_unref(current_conn);
		current_conn = NULL;
	}
	
	advertising_stop();
	advertising_start();
}

I have a service with 2 characteristics and one configuration

        BT_GATT_CCC(rx_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
this is just for disable/enable notifications function.


I use nrf connect application on my mobile phone, and i connect to it, but after disconnecting i cannot again connect to the device.

Also adding advertising data:
// Declaring the advertising data
struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	BT_DATA(BT_DATA_NAME_COMPLETE, ble_dev_name, 16),
};

// Declaring the scanning data
struct bt_data sd[] = {
	BT_DATA(BT_DATA_UUID128_ALL, uuid_128, sizeof(uuid_128)),
	BT_DATA(BT_DATA_MANUFACTURER_DATA, manufacturer_data, sizeof(manufacturer_data))
};

// Declaring advertising parameters
static struct bt_le_adv_param adv_param = 
{
	.options = BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_IDENTITY, 	/* Connectable advertising and use identity address */
	.interval_max = BT_GAP_ADV_FAST_INT_MAX_1,							/* 0x30 units, 48 units, 30ms */
	.interval_min = BT_GAP_ADV_FAST_INT_MIN_1,							/* 0x60 units, 96 units, 60ms */
	.peer = NULL														/* Set to NULL for undirected advertising */
};


I am using 2.9 version of nrf connect for vscode.
Parents Reply
  • Thanks for sharing the code. The issue was that you were increasing the reference count for the connection object with '2' in your connected callback, but you only released one of them in your disconnected callback. The advertiser does not resume until the reference count is 0. Solution is to only call bt_conn_ref() once. 

    You also had an endless loop in main() in the code you provided me. This will block other threads such as the logger thread.

Children
Related