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;
       }
    }
    

  • sorry Glen, I did not manage to test this as i am OoO due to sick child. I will test this as soon as i am back to office. Since this is an public ticket, hopefully someone chimes in some knowledge before i can test.

  • If I call bt_le_ext_adv_create after settings_load the error is -5 (-EIO), if I call it before settings_load the return code is -11 (-EAGAIN)

Reply Children
Related