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, 4 months ago.
Runtime advertising data updating
Hello,
I am trying to update the advertising data in real time. I have called clearAdvertisingPayload() after stopAdvertising() method and then regenerated the whole payload again as mentioned here https://developer.mbed.org/questions/55455/Updating-parameter-of-Payload-during-BLE/.
But when I scan with the nRF Master Control Panel I can see that the values aren't updated. Can anybody explain me what am I missing here please?
Thanks in advance. My code is:
BLEDevice ble;
const static char DEVICE_NAME[]= "OldName";
const static char DEVICE_NAME2[]= "NewName";
const static uint8_t AdvData[] = {"OldData"};
const static uint8_t AdvData2[] = {"NewData"};
void main() {
ble.init();
int counter = 1, i = 10;
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
ble.setAdvertisingType(GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED);
ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData, sizeof(AdvData));
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
ble.setAdvertisingInterval(160);
ble.startAdvertising();
while (true) {
if(counter++ == i) { //this is simply to execute this after the first time BLE starts advertising
ble.stopAdvertising();
ble.clearAdvertisingPayload();
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
ble.setAdvertisingType(GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED);
ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData2,sizeof(AdvData2));
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME2, sizeof(DEVICE_NAME2));
ble.setAdvertisingInterval(160);
ble.startAdvertising();
}
ble.waitForEvent();
}
}