My code is roughly based on:
I'm using SDK12.2, softdevice S132. The relevant parts of code are:
static uint8_t bapi_adv_data[14] = {
0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8, 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2
};
static ble_advdata_manuf_data_t manuf_data = {
.company_identifier = 0x0410,
.data = {
.size = 14,
.p_data = bapi_adv_data
}
};
static ble_gap_adv_params_t adv_params = {
.type = BLE_GAP_ADV_TYPE_ADV_IND,
.p_peer_addr = NULL,
.fp = BLE_GAP_ADV_FP_ANY,
.interval = APP_CONNECTABLE_ADV_INTERVAL,
.timeout = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED
};
static ble_advdata_t adv_packet = {
.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE,
.name_type = BLE_ADVDATA_FULL_NAME,
.p_manuf_specific_data = &manuf_data
};
. . .
void connectable_advertising_init() {
adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND;
adv_params.interval = APP_CONNECTABLE_ADV_INTERVAL;
}
void non_connectable_advertising_init() {
adv_paramsp.type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
adv_paramsp.interval = APP_NON_CONNECTABLE_ADV_INTERVAL;
}
. . .
static void on_connect() {
non_connectable_advertising_init();
advertising_start();
}
static void on_disconnect(bluetooth_p this) {
sd_ble_gap_adv_stop();
connectable_advertising_init();
advertising_start();
}
. . .
void advertising_start() {
APP_ERROR_CHECK(sd_ble_gap_adv_start(&adv_params));
this->advertising = 1;
sd_ble_gap_tx_power_set(4);
}
Intervals are 120 & 240 ms, well inside the legal ranges. The on_connect()
and on_disconnect()
functions are called from with the event handler. At various times in the program I change the manuf. data and call ble_advdata_set(&adv_packet, NULL)
.
I never get any errors, and while not connected, I can see the 63-byte advertising packets with a sniffer and see my data in them. But after connecting, and verifying that advertising_start()
got called and did not return any error, I see only some 26-byte packets on the sniffer that don't contain any of my data, and likewise my app sees no useful data.
Is there a way I can trap advertising events to debug this? (I understand the SDK12.2 advertising library doesn't do the non-connectable thing, so I can't use it, is that right?) Is there something obvious I'm doing wrong that's causing advertising to fail while connected?
Update:
As I was writing this, I thought maybe I was hitting the packet size limit, so I trimmed four bytes. Now I seem to be getting 59-packets including my data during the connection, but they are happening at 120 ms intervals instead of 240, and my app doesn't see them, so there's still something odd going on here.