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

Changing advertisement data in every packet

Hi,

I need to change advertisement data while advertising. The goal is to set new data for every packet. Firstly, I was trying to put new value like this, but it didn't work:

#... int COUNTER = 1; uint8_t data[] = "123456789123456"; #... // Enter main loop. for (;;) { COUNTER = COUNTER + 1; if (COUNTER == 14) COUNTER = 0; data[3] = (uint8_t) COUNTER; power_manage(); } (modified code from ble tutorial: devzone.nordicsemi.com/.../)

After that, I have read this post: devzone.nordicsemi.com/.../

As I understand now, I was changing memory and that did not make any effect on my advertising. In order to do so, I need to use sd_ble_gap_adv_data_set(). When I try to put it in main loop with COUNTER value as p_data it does not work and I have no idea what is wrong.

What should I change in order to make it work? How can I solve this problem? Are there any other approaches?

Parents
  • The solution here is to use radio notifications. You will have to change the advertisement packet every time the radio has been active, which typically is after every advertisement interval. You will have to setup a callback function in ble_radio_notification_init(…) that changes the advertisement packet.

    A user has uploaded his implementation of this solution here, where he switches between different eddystone-format advertising packets using the callback function eddystone_interleave(..).

  • Is this a kind of beacon application? You are not connecting any devices to the nRF51, only advertising? What kind of data are you advertising? Is it temperature or battery voltage that is changing?

    The advertising packet only supports up to 31 bytes, so the scan response data packet is an optional "secondary" advertising payload which allows scanning devices that detect an advertising device to request a second advertising packet. This allows you to send two advertising frames with a total payload of 62 bytes.

    See this tutorial and this blog post about advertising.

Reply
  • Is this a kind of beacon application? You are not connecting any devices to the nRF51, only advertising? What kind of data are you advertising? Is it temperature or battery voltage that is changing?

    The advertising packet only supports up to 31 bytes, so the scan response data packet is an optional "secondary" advertising payload which allows scanning devices that detect an advertising device to request a second advertising packet. This allows you to send two advertising frames with a total payload of 62 bytes.

    See this tutorial and this blog post about advertising.

Children
No Data
Related