I am developing software with the following features.
- Communicates between two boards with nRF52840, nRF5 SDK 15.3.0, and its S140
- Activate both extended advertising and scanning on each node
Parameters: BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED, BLE_GAP_PHY_CODED, etc. - Repeat advertising and scanning alternately.
One is advertising, the other is scanning
The software having above features is operating normally. But I am wondering about the following:
[Question 1]
If the node stop scanning during advertising, it can communicate normally.
(Call nrf_ble_scan_stop() just before the advertising starts and nrf_ble_scan_start() after the advertising ends.)
But if the node do not stop scanning during advertising, the communication success rate will drop extremely.
(Almost no communication)
Is this correct behavior? Or can it be improved by changing parameters or API calls?
*I understand from the ticket below that this is the correct behavior/limitation.
devzone.nordicsemi.com/.../simultaneous-scanning-and-extended-advertising-with-sdk-15-2
*I understand from the ticket below that this is the correct behavior/limitation.
devzone.nordicsemi.com/.../simultaneous-scanning-and-extended-advertising-with-sdk-15-2
[Question 2]
How do I embed long length unique data into its advertising? The following is my source code.
Please correct any mistakes in the following methods.
And if correct, please tell me how many bytes can be sent this way.
Currently I am sending 185 bytes, but I want to send as much data as possible.
Please correct any mistakes in the following methods.
And if correct, please tell me how many bytes can be sent this way.
Currently I am sending 185 bytes, but I want to send as much data as possible.
/* For advertising */
static uint8_t m_enc_advdata[BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_MAX_SUPPORTED]; /**< Buffer for storing an encoded advertising set. */
static ble_gap_adv_data_t m_adv_data =
{
.adv_data =
{
.p_data = m_enc_advdata,
.len = BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_MAX_SUPPORTED
},
.scan_rsp_data =
{
.p_data = NULL,
.len = 0
}
};
static bool advertising_data_set(void)
{
ret_code_t ret;
ble_gap_adv_params_t const adv_params =
{
.properties =
{
.type = BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED,
},
.p_peer_addr = NULL,
.filter_policy = BLE_GAP_ADV_FP_ANY,
.interval = 80,
.duration = 80,
.primary_phy = BLE_GAP_PHY_CODED,
.secondary_phy = BLE_GAP_PHY_CODED,
.max_adv_evts = 1,
};
ble_advdata_t const adv_data =
{
.name_type = BLE_ADVDATA_NO_NAME,
.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE,
.include_appearance = false,
};
/* set long length unique data to m_enc_advdata */
memcpy(m_enc_advdata, <long length unique data>, 185);
/* call sd_ble_gap_adv_set_configure without calling ble_advdata_encode() */
ret = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
}
/* For scanning */
NRF_BLE_SCAN_DEF(m_scan); /**< Scanning Module instance. */
static ble_gap_scan_params_t m_scan_param = /**< Scan parameters requested for scanning and connection. */
{
.active = 0x00,
.interval = 170,
.window = 170,
.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
.timeout = 0,
.scan_phys = BLE_GAP_PHY_CODED, // Choose only one of the following scan_phys
.extended = 1,
};
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_ADV_REPORT:
{
<In this part, referring m_scan.scan_buffer.len and m_scan.scan_buffer.p_data>