This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Simultaneous execution of extended advertisement and scanning

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

[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.
/* 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>
            

  • Dear Jakobsen,

    Thank you for providing information.
    I tried to understand the specifications based on the information you recommend, but it was too difficult for me to understand.

    So I want to change the question.
    All I want to do is broadcast long data with unlimited values in the following modes:

    • CodedPhy
    • BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED

    Could you please introduce your recommended example that meets this condition?
    I want to send as long a data as possible, but it doesn't have to be 255 bytes.

    In actual operation, it is unknown what value will be sent.
    Therefore, I want to avoid getting an error when sending a value that meets certain conditions.
    As I've already explained, my source code is similar to the example in the document below.

    • nRF5_SDK_15.3.0_59ac345/components/softdevice/s140/doc/s140_nrf52_6.1.0_migration-document.pdf

    But, as you say, this method seems to return an error depending on the value we send.
    So I'd like to try another method that doesn't cause an error no matter what value I send.

    Best Regards,

  • Hi,

    I am sorry for the late reply. Joakim has been out of office on vacation. I am trying to see if I understand your question but I don't understand what you mean with the following:

    Seno said:
    In actual operation, it is unknown what value will be sent.
    Therefore, I want to avoid getting an error when sending a value that meets certain conditions.

     And the example you are reffering to is not an example, but a guide to migrate to the newest version of Softdevice S140 from older versions.

    Can you explain more in detail what you are struggling with?

    Best regards,

    Marjeris

  • Dear msromero,

    Thank you for your reply.
    Below is a summary of my latest questions/requests.

    <My latest question/requirement>
    What is required of my software is to send and receive up to 255 bytes of data over long range broadcasts. Because of this requirement, I chose CodedPhy and extended advertising in nRF5_SDK_15.3.0 for nRF52840.
    Initially, I searched for a suitable example, but couldn't find an example that fits perfectly.
    Therefore, I developed my own software by referring to some examples.

    My current software can send up to 236 bytes as described in the past, but if I try to send more data than this, the API sd_ble_gap_adv_set_configure will return NRF_ERROR_INVALID_LENGTH as an error.
    Please tell me the cause of this error and how to improve it and send up to 255 bytes long.
    I thought my problem could be solved if you could provide a good example of sending up to 255 bytes.

    <My past comments you wondered>
    In actual operation, it is unknown what value will be sent.
    Therefore, I want to avoid getting an error when sending a value that meets certain conditions.

    <Intent of the above comment>
    From Joakim I received the reply that the above error would occur if the format allowed by BLE was violated.
    And I was advised to check the BLE specification etc. about what format is acceptable.
    However, the BLE specification is difficult for me, and I don't understand what value is acceptable and what value is rejected as an error.

    Currently my software seems to be able to successfully send up to 236 bytes.
    However, the combination of data that can be tested is limited.
    In the future, when it sends a specific value, it may get a format error.
    Such risks/concerns should be avoided by the time the software is officially released.

    <Status of my first questions>
    I have asked two questions, [Question 1] and [Question 2] so far.
    Of these, [Question 1] has been resolved but [Question 2] has not yet been resolved.

    Best Regards,

  • Hi.

    Sorry about the delay. I've been out of office a while.

    From what I can see, you are able to send 185 bytes in your advertising packet? Which means that you have sucessfully enabled extended advertising.

    You can refer to the RSCS example for an example on how to use extended advertising.

    Br,
    Joakim

  • Hi.
    Sorry for the late reply.

    Regarding the API sd_ble_gap_adv_set_configure, in my application, when I send data 148 bytes long, I get another error NRF_ERROR_INVALID_DATA.
    To solve this problem, I need to understand exactly how to program extended advertising that you recommend.

    You recommended in the last comment to refer to the RSCS example.
    In my response to this, I referred to the following files.

    <File: nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\ble_app_rscs\main.c>

    (line: 160) BLE_ADVERTISING_DEF(m_advertising); /**< Advertising module instance. */
    (line: 848) init.config.ble_adv_extended_enabled = true;
    (line: 852) err_code = ble_advertising_init(&m_advertising, &init);


    <File: nRF5_SDK_15.3.0_59ac345_original\components\ble\ble_advertising\ble_advertising.c>

    (line 431) uint32_t ble_advertising_init(ble_advertising_t * const p_advertising,
    (line 461) if (p_advertising->adv_modes_config.ble_adv_extended_enabled == true)
    (line 462) {
    (line 463) #ifdef BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_CONNECTABLE_MAX_SUPPORTED
    (line 464) p_advertising->adv_data.adv_data.len = BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_CONNECTABLE_MAX_SUPPORTED;
    (line 465) #else
    (line 466) p_advertising->adv_data.adv_data.len = BLE_GAP_ADV_SET_DATA_SIZE_MAX;
    (line 467) #endif // BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_CONNECTABLE_MAX_SUPPORTED
    (line 468) }
    (line 474) ret = ble_advdata_encode(&p_init->advdata, p_advertising->enc_advdata, &p_advertising->adv_data.adv_data.len);
    (line 505) ret = sd_ble_gap_adv_set_configure(&p_advertising->adv_handle, NULL, &p_advertising->adv_params);

    <File nRF5_SDK_15.3.0_59ac345_original\components\softdevice\s140\headers\ble_gap.h>

    (line 250) #define BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_CONNECTABLE_MAX_SUPPORTED (238) /**< Maximum supported data length for an extended connectable advertising set. */

    The following are my understanding.

    1) The example which you recommend seems to support extended advertising.
    If BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_CONNECTABLE_MAX_SUPPORTED is defined, the data length is extended to 238 bytes.

    2) The API ble_advdata_encode is called.

    3) However, the API sd_ble_gap_adv_set_configure is called by setting NULL to the second parameter.
    I understand that this example supports extensions, but no extended data is set.


    Is my understanding above correct?
    If so, please show me how to modify the above RSCS example to send 148 bytes of our application-dependent data.

    Best Regards,

Related