9 years, 9 months ago.

nrf51 update advertisement

I am trying to update advertisement data in beacon code in a frequent basis, and I came up with the following:

while(1){
beaconPayload//update array data info
ble.stopAdvertising();
ble.clearAdvertisingPayload();
ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA,beaconPayload,sizeof(beaconPayload));
ble.startAdvertising();
wait(1);
}

This seems to work but I am sure there is a better way to update the packets without the need to stop and start advertising in the loop.

Digging into the code itself, and the library uses sd_ble_gap_adv_data_set() to encode the data for update (and SDK shows the same method). I am wondering if there is a way to write using sd_ble_gap_adv_data_set() and update the SERVICE_DATA that way without the stop and start functions?

Thanks!

Question relating to:

The nRF51822-mKIT is a low cost ARM mbed enabled development board for Bluetooth® Smart designs with the nRF51822 SoC. The kit gives access to all GPIO pins via pin headers …

1 Answer

9 years, 9 months ago.

A new API has been added to address this issue: setAdvertisingPayload() You should now be able to clear the advertising payload, re-accumulate a new payload, and then reset it for advertisements using this API. I've tested it and it worked fine.

Thanks for bringing this up.

rohit.

Is there an example to do that? I seem to have trouble using that API. Thanks

posted by lawrence W 09 Sep 2014