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
  • Hello,

    Does the device start connectable advertising again after the disconnect?  In other words, if you restart scanning in the nRF Connect app after the disconnect, can you still discover your device? 

    Best regards,

    Vidar

  • no, i cannot discover my device on application. 

  • This indicates that the advertiser is not re-started on disconnect. Please also post your implementation of advertising_start().

  • // 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 */
    };
    
    // 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))
    };
    
    /*
    	@brief Function for starting advertising.
    */
    void advertising_start(void)
    {
    	if(ble_status == BLE_IDLE){
    		int err = bt_le_adv_start(&adv_param, ad, ARRAY_SIZE(ad), sd,
    					ARRAY_SIZE(sd));
    		
    		if (err) {
    			LOG_ERR("Advertising failed to start (err %d)", err);
    		}
    		ble_status = BLE_ADV;
    	}
    }

Reply
  • // 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 */
    };
    
    // 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))
    };
    
    /*
    	@brief Function for starting advertising.
    */
    void advertising_start(void)
    {
    	if(ble_status == BLE_IDLE){
    		int err = bt_le_adv_start(&adv_param, ad, ARRAY_SIZE(ad), sd,
    					ARRAY_SIZE(sd));
    		
    		if (err) {
    			LOG_ERR("Advertising failed to start (err %d)", err);
    		}
    		ble_status = BLE_ADV;
    	}
    }

Children
Related