I'm using an ESP32 C3 soc to send out Bluetooth Extended Advertisements. Most of the sample code that I've found illustrates sending out one to many static messages. I have a need to send out an message that is dynamic in nature which is posing a problem.
I'm developing this with Ardurino and am useing the Expressif Bluetooth Libraries.
I have a method that will stop the advertisements, then update the advertising parameters and then turn the advertisements back on. The issue that I'm running into is that when I update the advertising data
ble_status = esp_ble_gap_config_ext_adv_data_raw(0, length, ble_message);
in real time this responds with a E (89916) BT_BTM: LE EA SetAdvData: cmd err=0x12 even though the shutdown of the advertisements is successful, and restart is also successful.
Is there another approach that's needed to handle the use case of an extended advertisement that needs to change with time?
int transmit_ble2(uint8_t *ble_message,int length) {
esp_err_t ble_status;
bool status;
static int advertising = 0;
int advertno = 0;
if(advertising)
{
const uint8_t inst[] = {0x00};
status = advert.stop(0, inst);
status = advert.remove(0);
status = advert.clear();
advertising = 0;
}
advert.setAdvertisingParams(advertno, &ext_adv_params_1M);
ble_status = esp_ble_gap_config_ext_adv_data_raw(0, length, ble_message);
Serial.println(ble_status);
advert.setDuration(0);
advert.setScanRspData(advertno, sizeof(raw_scan_rsp_data_coded), &raw_scan_rsp_data_coded[0]);
advert.setInstanceAddress(advertno, addr_1m);
status = advert.start(1,advertno);
advertising = 1;
return 0;
}