Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 5 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:
1 Answer
10 years, 4 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.