Bluetooth connexion issue

Hello community, 
I'm trying to implement BT service on my project to be able to connect with my phone 
for information my project displays data from sensors(BME280, INA219, MPU6050)  connected to my D-kit 
i'm using nrf connect V1.8.0 and NRF5340dk
i got inspired from this BT tutorial to create my services 
but in terms of BT connexion i don't get the device on my ophone when i scan devices around 
which means that connexion isn't established
and i got this message "Advertising failed to start (err-11)"
i will attach below my output display 

i tried to flash my D-kit directly but it didn't work 
and i tried to activate the BT but in vain too 
i tried to use this function

    //Start advertising
	err = bt_le_adv_start(BT_LE_ADV_PARAM(
							BT_LE_ADV_OPT_CONNECTABLE
							|BT_LE_ADV_OPT_ONE_TIME
							|BT_LE_ADV_OPT_USE_NAME,
							160, 	// units of 0.625ms
							1600),	// units of 0.625ms
						ad, ARRAY_SIZE(ad),
						sd, ARRAY_SIZE(sd));

Can you guys help  by telling me what's wrong on this situation 
why can't i get the bt to advertise 
do i missing something on the main or on the activation 
by the way my prj.conf should be good and i will liked below
 
CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_MAX_CONN=1
CONFIG_BT_L2CAP_TX_BUF_COUNT=5
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="My_Device"
CONFIG_BT_DEVICE_APPEARANCE=962

CONFIG_HEAP_MEM_POOL_SIZE=2048

# This example requires more workqueue stack
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

CONFIG_STDOUT_CONSOLE=y
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_SENSOR=y
CONFIG_I2C=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_UART_CONSOLE=n
CONFIG_RTT_CONSOLE=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_PRINTK=y
CONFIG_INA219=y
CONFIG_BME280=y

CONFIG_SHELL_BACKEND_SERIAL=y


Can you help me with this please 
i will be very grateful 

Parents
  • Hi,

    I do not see your code, but I assume you print "Advertising failed to start" if bt_le_adv_start() returns an error (and in that case it is only natural that you are not able to see the device from your phone when scanning, as it does not advertise). bt_le_adv_start() returns -EAGAIN if Bluetooth is not ready, so without seeing your code my guess is that you call this function too early. If need to wait until Bluetooth is enabled (for instance by using a callback that you provide to the call to bt_enable(), as you can see form the beacon sample.

  • hi, 
    thank you for your reply 
    infact i checked my code and i'm calling the function in the right place 

        int err = 0;
    	uint32_t number = 0;
    
    	printk("Starting BLE Service\n");
    	
    	err = bt_enable(bt_ready_data_data_data_data_work_work_work_work_fn);
    
    	if (err) 
    	{
    		printk("BLE initialization failed (err %d)\n", err);
    		error(); //Catch error
    	}
    	
    	/* 	Bluetooth stack should be ready in less than 100 msec. 								\
    																							\
    		We use this semaphore to wait for bt_enable to call bt_ready before we proceed 		\
    		to the main loop. By using the semaphore to block execution we allow the RTOS to 	\
    		execute other tasks while we wait. */	
    	err = k_sem_take(&ble_init_ok, K_MSEC(500));
            
    	if (!err) 
    	{
    		printk("Bluetooth initialized\n");
    	} else 
    	{
    		printk("BLE initialization did not complete in time\n");
    		error(); //Catch error
    	}
    
    	err = my_service_init();
    
    	for (;;) 
    	{
    		// Main loop
    		my_service_send(my_connection, (uint8_t *)&number, sizeof(number));
    		number++;
    		k_sleep(K_MSEC(1000)); // 1000ms
    	}
    

    if you're wondering what hae put in my function bt_ready_data_data_data_data_work_work_work_work_fn
    i'm linking it below 
    static void bt_ready_data_data_data_data_work_work_work_work_fn(struct k_work *work)
    {
            int err;
    	if (err) 
    	{
    		printk("BLE init failed with error code %d\n", err);
    		return;
    	}
    
    	//Configure connection callbacks
    	bt_conn_cb_register(&conn_callbacks);
    
    	//Initalize services
    	err = my_service_init();
            //printk("Bluetooth initialized \n");
    
    	if (err) 
    	{
    		printk("Failed to init LBS (err:%d)\n", err);
    		return;
    	}
    
    
    	//Start advertising
    	err = bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad),
    			      sd, ARRAY_SIZE(sd));
    	if (err) 
    	{
    		printk("Advertising failed to start (err %d)\n", err);
    		return;
    	}
    
    	printk("Advertising successfully started\n");
    
    	k_sem_give(&ble_init_ok);
    }
    


    if functions are being called in the right place, then what is making the BT service failing to advertise ?
    can you help me find out please 
    Kindly,

  • I see. However, there seems to only be one condition where -EAGAIN (-11) would be returned in the case of legacy/normal advertising, and that is when Bluetooth is not ready. I do not see from these snippets why this would be a problem, but could you check with bt_is_ready() before calling bt_le_adv_start()? If it is not, wait a bit before you try. Or just try first and if it returns -EAGAIN try again at a later point.

  • Hello,
    i tried to search for the function bt_le_is_ready but i can't find it no where 
    can you provide me with an example code where it's been used 
    thank you in advance 

Reply Children
No Data
Related