This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Error when trying to enable extended advertising on code based on NUS example

Hi,

I'm working on an nRF5340 project using nRF Connect SDK v1.7.0 with VS Code. I started my project with the NUS example.

I've been able to customize the standard/legacy advertising packets as required by my customer with no problem using bt_le_adv_start(), but they also want me to be able to use extended advertising in certain circumstances.

In order to do that I see that I have to not only switch to calling bt_le_ext_adv_start, but also create an advertising set using bt_le_ext_adv_create. I found an example that does that for reference (iso_broadcast), but when I call bt_le_ext_adv_create I get a -5 return code (-EIO).

The full sequence of calls is bt_le_ext_adv_create calls le_ext_adv_param_set, which calls bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_EXT_ADV_PARAM, buf, &rsp);

The send_sync function gets a 1  from this call: status = cmd(buf)->status;

That causes the function to send the -5 back up the chain.

What am I doing wrong?

Thanks,

Glen

Parents
  • can you show some code snippets on the details of arguments to bt_le_ext_adv_create I can try to replicate that on my end. That error looks like a missing feature but cannot confirm it before I can see it.

  • Here's a trimmed down version with the problem section. Most of this is from the peripheral_uart (NUS) example that I used as a starting point, I just added the bt_le_ext_adv_create stuff.

    static void connected(struct bt_conn *conn, uint8_t err);
    static void disconnected(struct bt_conn *conn, uint8_t reason);
    #ifdef CONFIG_BT_NUS_SECURITY_ENABLED
    static void security_changed(struct bt_conn *conn, bt_security_t level,enum bt_security_err err);
    #endif
    #if defined(CONFIG_BT_NUS_SECURITY_ENABLED)
    static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey);
    static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey);
    static void auth_cancel(struct bt_conn *conn);
    static void pairing_confirm(struct bt_conn *conn);
    static void pairing_complete(struct bt_conn *conn, bool bonded);
    static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason);
    #endif
    static void bt_receive_cb(struct bt_conn *conn, const uint8_t *const data, uint16_t len);
    void error(void);
    
    //== Global Variables ========================================================
    
    static K_SEM_DEFINE(ble_init_ok, 0, 1);
    
    static const struct bt_data m_scan_response_data[] = 
    {
       BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
    };
    
    static struct bt_conn *current_conn;
    static struct bt_conn *auth_conn;
    
    static struct bt_conn_cb conn_callbacks = 
    {
       .connected    = connected,
       .disconnected = disconnected,
       #ifdef CONFIG_BT_NUS_SECURITY_ENABLED
          .security_changed = security_changed,
       #endif
    };
    
    #if defined(CONFIG_BT_NUS_SECURITY_ENABLED)
    static struct bt_conn_auth_cb conn_auth_callbacks = 
    {
       .passkey_display = auth_passkey_display,
       .passkey_confirm = auth_passkey_confirm,
       .cancel = auth_cancel,
       .pairing_confirm = pairing_confirm,
       .pairing_complete = pairing_complete,
       .pairing_failed = pairing_failed
    };
    #else
    static struct bt_conn_auth_cb conn_auth_callbacks;
    #endif
    
    static struct bt_nus_cb nus_cb = 
    {
       .received = bt_receive_cb,
    };
    
    static struct bt_le_ext_adv *m_extended_advertising_set;
    static struct bt_le_ext_adv_start_param ext_adv_start_param = {
    	.timeout = 0,
    	.num_events = 0,
    };
    
    //============================================================================
    
    //----------------------------------------------------------------------------
    // Name  : bluetooth_init
    // Desc  : Configure Bluetooth services and start advertising
    // Ins   : none
    // Outs  : none
    //----------------------------------------------------------------------------
    void bluetooth_init(void)
    {
       int err = 0;
    
       bt_conn_cb_register(&conn_callbacks);
    
       if (IS_ENABLED(CONFIG_BT_NUS_SECURITY_ENABLED)) 
       {
          bt_conn_auth_cb_register(&conn_auth_callbacks);
       }
    
       err = bt_enable(NULL);
       if (err) 
       {
          error();
       }
    
       printk("Bluetooth initialized");
    
       k_sem_give(&ble_init_ok);
    
       if (IS_ENABLED(CONFIG_SETTINGS)) 
       {
          settings_load();
       }
    
       err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME, NULL, &m_extended_advertising_set);  
       if (err) 
       {
          error();
       }
    
       err = bt_nus_init(&nus_cb);
       if (err) 
       {
          LOG_ERR("Failed to initialize UART service (err: %d)", err);
          return;
       }
    }
    

  • Will your example work on my nRF5340 eval board where I could debug it?

  • i used 5340 DK, so not sure why you are seeing any difference.  Have you run the hr_coded example (unedited) on your eval board? does it run normally?

  • I just tried it and I get the same error from bt_le_ext_adv_create. I'm using VSCode with SDK 1.7.0. The newer SDK isn't supposed to have any relevant changes but I guess I could upgrade and see what happens.

  • I upgraded to all the latest stuff and I get the same thing... at line 83 of main.c in the create_advertising_coded function I get -5 back from bt_le_ext_adv_create().

  • sorry for the late reply Glen, 

    I need to get your full setup, obviously there is some difference between your and my setup. 

    Have you set CONFIG_BT_EXT_ADV=y in your config? Not sure what else is different.

Reply Children
  • Yes CONFIG_BT_EXT_ADV is y. I'm not sure what to try next either as we're running the same HR CODED example using the same hardware and tools and getting different results.

    How are you verifying that it works - is it just working, or are you looking at the return codes? Maybe the return code doesn't matter and it'll end up working anyway if I just let it run?

  • Susheel Nuguru said:
    I tried to use your code in hr_coded example and adding settings or BT_LE_EXT_ADV_NCONN_NAME in bt_le_ext_adv_create passes normally. Not sure what else is different in your setup but i cannot find anything that is relevant to this issue to be different than your code snippet and this hr_coded exampe  

    I tried hr_coded example with changes to the create function to match yours and the error code returned was 0. 

    Glen M said:
    Maybe the return code doesn't matter and it'll end up working anyway if I just let it run?

    That odes not sound right, error codes other than 0 shows failure and letting it run anyway to expect it to work is very risky.

    Have you tried the hr_coded example with minor changes to the arguments to bt_le_ext_adv_create and run it in the debugger, set a breakpoint at this function and see what error code you get? If this example works for you, then we need to take a closer look at your setup.

Related