I'm developing a broadcast advertiser (non-connectable, non-scannable) on an nRF52833 with the S113 SoftDevice, and am working from the Beacon Transmitter Sample Application example.
I would like to make it so that prior to each advertisement, it dynamically computes some values and includes those in the advertisement data (manufacturer-specific data). For example, let's say that I'd like to include in each advertisement the number of seconds that the beacon has been operational since it was last reset (i.e. a constantly-changing value).
So, I have two questions:
- Is there a way to add a "hook" (or an event handler) that is triggered immediately before the advertisement is transmitted? This seems like it would be the ideal place to do such calculations. I took a look through the various events, thinking I might be able to do this on the event handler, but I can't find an event that corresponds to pre-advertisement-transmission. If there is no such hook/event, any recommendations on the best way to do this?
- What is the proper way to update the advertised data without stopping/restarting the advertising? The sd_ble_gap_adv_set_configure function seems like the right one, but it's unclear how to use it while the advertising is still running, without accidentally corrupting the data being transmitted or ending up with a memory leak where old buffers aren't freed.