Updating scan response packet whilst advertising

In my application, I'm using the Scan Response Packet to transmit some device related information, rather than requiring Clients to connect to get this.  I'm using NCS v2.0.0 and testing on an nRF52-DK.

I'm using the following to store the scan response information, and I update the information in there whenever it changes.

static struct bt_data sd[] = {
    BT_DATA(BT_DATA_MANUFACTURER_DATA, NULL, BT_GAP_ADV_MAX_ADV_DATA_LEN-2),
};

On first boot up, when I start BLE, I make a call to:

err = bt_le_adv_start(BT_LE_ADV_CONN_LSR_AD, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));

That successfully updates the scan response packet.  But if I subsequently attempt to update the scan response packet whilst I'm still advertising, via a call to:

err = bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));

Then the scan response packet doesn't change.  I'm checking the result of err after this function call, and its returning 0, which indicates that its been successful.

The only way I seem able to get the scan response packet to update correctly is if I:

  1. Stop advertising
  2. Update scan response packet
  3. Restart advertising

Is there a way to dynamically update the scan response packet whilst advertising?  Or do I need to follow the process of stop, update, restart?

Cheers,

Mike

Parents
  • Hi Hieu,

    Got it sorted.  Had nothing to do with how I had set everything up, but was in fact related to an if() statement I had my bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)); call inside.  Basically, the if() statement wasn't ever becoming true, so I wasn't ever sending out the updated scan response data.  Should have checked my code better!

    A quick related question - the if() statement was basically checking to see if I had disconnected and was advertising again, as I update some of the info that I send out on the scan response packet via a BLE connection to a client.  So, before I attempt to update the scan response packet I was doing a check to ensure I was back advertising.

    I do this with a bool that I set to 

    bt_status = BLE_ADVERTISING;
    within my .disconnected call back.  But that basically assumes that if I'm disconnected, I'm advertising, as I don't actually know of any way of checking the current BLE status.  It could, for example, have stopped completely.
    Do you know if there are any API's that will return the current BLE status?
    Cheers,
    Mike
  • Hi Mike,

    Glad to know you got it worked out.

    Unfortunately, I also don't think there is any API to help you directly get the advertising status.

    However, I found that if you use Advertisement Set, you can setup some helpful callback while calling bt_le_ext_adv_create().

    If you feel like you have a strong use case, I think you can open a feature request in the Zephyr project. If you do, please share it with the community by giving the link here.

    Hope that helps.

    Best regards,

    Hieu

Reply Children
No Data
Related