This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Zephyr issues with limited advertising events on nRF52840

I've previously successfully done interval advertisements using a SoftDevice with Nordic's previous (non-Zephyr) sdk, but I'm having issues replicating it on Zephyr.

Our desired goal is as follows: we want to be able to send exactly 3 advertising events, 200 ms apart, and then stop advertising until the next event, in which case we want to send exactly 3 different advertising events, so on and so forth.

However, I'm having several issues on Zephyr:

First and foremost, it appears that BLE advertisements continue to be sent, rather than stopping at 3 events (though my sent callback does fire after 3 events are sent). I'm using the nRF Connect bluetooth app on my tablet to confirm this is the case, and the signal strength and interval numbers continue to update.

Secondly, the interval doesn't seem to change even when I increase the intervals from the default minimum of 100 ms (BT_GAP_ADV_FAST_INT_MIN_2) to the appropriate hex value for 200ms.

Finally, and most problematic, is that after the first advertisement set gets sent I see the following errors when I call the function to start advertising again:

<wrn> bt_hci_core: opcode 0x2039 status 0x0c
<err> bt_hci_core: Failed to start advertiser

I found the following issue in git: https://github.com/zephyrproject-rtos/zephyr/issues/31254

But, in our application we are not connectable and not scannable so it would seem as though this shouldn't be an issue in this case.

My code for initialization of the extended advertising is as follows (with my modified code to support intervals of 200ms), ignoring my var initialization for beacon_packet and adv:

#define BLE_INT                         (0x140) // N * 0.625. corresponds to dec. 320; 320*0.625 = 200ms
#define BLE_ADV_TIMEOUT                 (80)  // N * 10ms for advertiser timeout
#define BLE_ADV_EVENTS                  (3)

bt_le_ext_adv_create(BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, BLE_INT, BLE_INT, NULL), &conn_callbacks, &adv);
bt_le_ext_adv_set_data(adv,beacon_packet, ARRAY_SIZE(beacon_packet), NULL, 0);
bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_PARAM(BLE_ADV_TIMEOUT, BLE_ADV_EVENTS));

My attempt at subsequent advertisements after the initialization is as follows:

bt_le_ext_adv_set_data(adv,beacon_packet, ARRAY_SIZE(beacon_packet), NULL, 0);
bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_PARAM(BLE_ADV_TIMEOUT, BLE_ADV_EVENTS));

Any help pointing me in the right direction would be appreciated! Again, this all worked well on the Nordic SDK using SoftDevices and I would really love to achieve the same functionality in Zephyr.

Parents Reply
  • Hi,

    While I was able to program this sample code onto my device fine, I am not able to validate it with testing. I've been using nRF Connect on my Android tablet to validate bluetooth advertising. Previously, I was able to successfully see advertising events with Zephyr non-extended advertising, and successfully had this interval method with 3 events working on the previous sdk also showing up in this app.

    But, I don't see any advertising data with the current sample code. How do you recommend validating it? Maybe I'm missing something in testing?

    Thanks!

Children
  • Hi,

    First and foremost, it appears that BLE advertisements continue to be sent, rather than stopping at 3 events (though my sent callback does fire after 3 events are sent). I'm using the nRF Connect bluetooth app on my tablet to confirm this is the case, and the signal strength and interval numbers continue to update.

    When you tested this, this was also with bt_le_ext_adv_start()? i.e. do we know if the tablet supports advertising extensions(AE)?

    NathanML said:
    But, I don't see any advertising data with the current sample code. How do you recommend validating it?

     Do you see it if you increase BLE_ADV_EVENTS? maybe from 3, to e.g. 50?

  • Hi,

    I was hoping you might be able to tell me that- does the nRF Connect Android app support advertising extensions?

    Because it worked with the previous sdk, I'm assuming that it does. Unless the way that the previous sdk did advertising events (by setting max_adv_events in the structure shown below) was not with extended advertising:

    static ble_gap_adv_params_t m_adv_params;                                  /**< Parameters to be passed to the stack when starting advertising. */

    And yes, in testing I increased the number of events significantly, as well as increased the timeout duration, and still did not see any advertising data showing up.

  • Hi,

    As we are not trying to actually do extended advertisements (but merely need to enable them in order to get event limited advertisements to work in Zephyr), I disabled the BT_LE_ADV_OPT_EXT_ADV option in parameter initialization and now the advertisements show up in nRF Connect- the tablet must not have supported extended advertising, which is fine since we didn't need that functionality in the first place.

  • NathanML said:
    I disabled the BT_LE_ADV_OPT_EXT_ADV option in parameter initialization and now the advertisements show up in nRF Connect

     Great!

    PS: In nRF Connect mobile app, you can go into "Device information", and you will get a list over the BLE features the phone/tablet supports.

  • Hi Nathan, I am trying to limit the number of advertising events to a small number. But seems like this can not be done using legacy advertisements in nRF Connect SDK. nRF5 SDK supported this, as you also mentioned in one of your answers. Can you please tell me how you managed to limit the number of events without enabling extended advertising? 

Related