9 years, 11 months ago.  This question has been closed. Reason: Duplicate question

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!