Hello. I have been trying to work with extended advertising between two nRF52840 boards using the SDK, but have had trouble in setting a long advertisement payload (as in, long enough to warrant using extended advertising).
I am basing my work off of the "ble_app_hrs_rscs_relay" example from the nRF52 SDK 15.2.0. (It is located in this directory of the SDK: <SDK root directory>\examples\ble_central_and_peripheral\experimental\ble_app_hrs_rscs_relay.
What I am trying to do is have a print statement inside of the scan event handler to print the payloads of advertisements that the boards detect. I am working with two nRF52840 boards, and while they can detect each other and execute the example successfully whether I have extended advertising enabled or disabled, I am having trouble setting the advertisement payload.
I am trying to set the payload of the extended advertisements inside of the advertising_init() function of main.c, like this:
...
#define test_manufacturer_data_len 200
#define test_sr_data_len 20
static uint8_t test_manufacturer_data[test_manufacturer_data_len];
static uint8_t test_sr_data[test_sr_data_len];
static uint8_t arbitrary_value = 0x03;
/**@brief Function for initializing the advertising functionality.
*/
static void advertising_init(void)
{
memset(test_manufacturer_data, arbitrary_value, test_manufacturer_data_len);
memset(test_sr_data, arbitrary_value, test_sr_data_len);
ret_code_t err_code;
ble_advertising_init_t init;
memset(&init, 0, sizeof(init));
...
init.advdata.p_manuf_specific_data->data.p_data = test_manufacturer_data;
init.advdata.p_manuf_specific_data->data.size = test_manufacturer_data_len;
init.srdata.p_manuf_specific_data->data.p_data = test_sr_data;
init.srdata.p_manuf_specific_data->data.size = test_sr_data_len;
init.config.ble_adv_extended_enabled = true;
...
}
In order to do testing, I added a line into the ble_advertising_init function inside of ble_advertising.h to print what the encoded advertisement data was as a hex string:
ble_advertising_init() {
...
ret = ble_advdata_encode(&p_init->advdata, p_advertising->enc_advdata, &p_advertising->adv_data.adv_data.len);
VERIFY_SUCCESS(ret);
PRINT_HEX("Value of encoded BLE advertising data:", p_advertising->enc_advdata, p_advertising->adv_data.adv_data.len);
...
}
To print the payload, I have this code in main.c (I have saved the adv data output from ble_advertising_init into expected_adv_data, and do a memcmp when scanning so that I don't print the advertisement payloads of every device I detect, only the other board I am working with that has the duplicate code on it)
static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
ret_code_t err_code;
ble_gap_evt_adv_report_t const * p_adv =
p_scan_evt->params.filter_match.p_adv_report;
ble_gap_scan_params_t const * p_scan_param =
p_scan_evt->p_scan_params;
...
if (memcmp(expected_adv_data, p_adv->data.p_data, sizeof(expected_adv_data)) == 0) {
PRINT_HEX("Value of p whitelist adv report", p_scan_evt->params.p_whitelist_adv_report->data.p_data, MAX_ADV_PRINT_LENGTH);
PRINT_HEX("Value of p not found", p_scan_evt->params.p_not_found->data.p_data, MAX_ADV_PRINT_LENGTH);
PRINT_HEX("Value of filter match", p_scan_evt->params.filter_match.p_adv_report->data.p_data, MAX_ADV_PRINT_LENGTH);
NRF_LOG_INFO("Length of data %d", p_scan_evt->params.filter_match.p_adv_report->data.len);
NRF_LOG_INFO("Length of data %d", p_scan_evt->params.p_not_found->data.len);
NRF_LOG_INFO("Length of data %d", p_scan_evt->params.p_whitelist_adv_report->data.len);
}
...
}
I am confused because the output of the printing of the encoded advertisement data from ble_advertising_init is 02010605030D18141802086E, even though I have set some data in the advertisement data to be my arbitrary value of 0x03; I don't see a large number of consecutive 0x03's anywhere there, and am not sure why. Is it because I set the manufacturer specific data of the advertisement packet wrong, or is that information actually somewhere else, and not in the encoded advertisement data?
The output I get from the print statements in the scan_evt_handler are also consistent with what I printed from ble_advertising_init (as in, they also print 02010605030D18141802086E and the lengths are all 12). Is there some other data structure that I can print other parts of the extended advertisement from (if I am not mistaken, the first advertisement packet is sent on one advertisement channel while the rest are sent on data channels, could this be related?)?