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

beacon advertise interval

hello Nordic

i am working with nrf52832, sdk 6.0, softdevice s132 v7.0

i read around the forum that i can advertise a beacon packet every 20 ms 

but in the ble_app_beacon example the interval for the advertisement is written to be minimum 100ms ?? so where did that 20 ms go ?

however, since i don't know how to change the data of the message while advertising i put a timer handler that stops the advertise, update the data and start it again.

i put the timer to go every 50 ms and the advertisement interval every 50 ms i put a pin toggle every time i receive a ble from the address i am filtering..

1. the time is not fixed, maybe some messages are lost or maybe not sent, i don't know 

2. the intervals are larger then 50 ms .. more to the 100 ms  when they are sometimes fixed 

can you advice on this matter ?

i need to be sending changeable data in a beacon at list 30 times in one second

best regards

Ziv

  • Hello Ziv,

    ziv123 said:
    which to my understanding copies all the defines and configs of one instance to the other  (not sure it is semantically correct to say it but you understood i belive)

    This might be the issue here, I do not think this is correct.
    What you are doing here is creating a shallow copy of the advdata struct. So, you are in fact just using the same single buffer.
    If you would like to check this, please try to print out the value of the advdata[advdata_idx] and advdata[advdata_next_idx] pointers following this line of code and see what they point to.
    If you are to do your updates like this, please ensure that you are making a deep copy of the advdata struct.
    Do this, and see if you then are able to update your advertising data using the _advdata_update function. I look forward to hearing if this resolves your issue!

    Please see this stackoverflow thread for a detailed explanation on shallow vs deep copying.

    Best regards,
    Karl 

  • hi Karl

    it did not solve (unless i did something wrong.. here is my code for init advertising with setting the 2 instances:

        // Build and set advertising data.
        memset(&advdata[0], 0, sizeof(advdata[0]));
        memset(&advdata[1], 0, sizeof(advdata[1]));
    
        advdata[0].name_type        = BLE_ADVDATA_NO_NAME;//BLE_ADVDATA_SHORT_NAME;//BLE_ADVDATA_NO_NAME;
        advdata[1].name_type        = BLE_ADVDATA_NO_NAME;
        advdata[0].flags            = flags;
        advdata[1].flags            = flags;
        advdata[0].p_manuf_specific_data = &manuf_specific_data;
        advdata[1].p_manuf_specific_data = &manuf_specific_data;
    
        // Initialize advertising parameters (used when starting advertising).
        memset(&m_adv_params, 0, sizeof(m_adv_params));
    
        m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
        m_adv_params.p_peer_addr     = NULL;    // Undirected advertisement.
        m_adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
        m_adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
        m_adv_params.duration        = 0;       // Never time out.
    
        err_code = ble_advdata_encode(&advdata[0], m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
        APP_ERROR_CHECK(err_code);
        err_code = ble_advdata_encode(&advdata[1], m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
        APP_ERROR_CHECK(err_code);
    
        err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
        APP_ERROR_CHECK(err_code);
    }

    and here is the code for the timer handler:

    static void data_update_timer_handler(void* p_context)
    {
        ret_code_t err_code;
    //    err_code = sd_ble_gap_adv_stop(m_adv_handle);
    //    APP_ERROR_CHECK(err_code);
    
        static uint8_t i = 0;
        if( i >= SET_VALUES_ARRAY )
        {
            i = 0;
        }
        uint8_t idx = i++;
        m_beacon_info[12] = spin_angle[idx];
        m_beacon_info[13] = (spin_direction[idx] | speed[idx]);
        NRF_LOG_INFO("%d",m_beacon_info[12]);
    
        manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info;
        manuf_specific_data.data.size   = APP_BEACON_INFO_LENGTH;
    
        if(0 == advdata_idx ) advdata_idx = 1;
        else if( 1 == advdata_idx) advdata_idx = 0;
    
        advdata[advdata_idx].p_manuf_specific_data = &manuf_specific_data;
        
        ble_advertising_advdata_update(&ble_adv ,&advdata[advdata_idx], NULL /*&advdata[advdata_next_idx]*/);
        //advdata_idx = advdata_next_idx;
    
    //    sd_ble_gap_adv_stop(m_adv_handle);
    //    err_code = ble_advdata_encode(&advdata[advdata_idx], m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
    //    APP_ERROR_CHECK(err_code);
    //    err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
    //    APP_ERROR_CHECK(err_code);
    //    err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
    //    APP_ERROR_CHECK(err_code);
    //    advdata_idx = advdata_next_idx;
    }

    it will be best if we would find out why this is not working but i wonder if it will not be easier to just download sdk 17, maybe there is such an example working in that sdk, of updating message data while advertising ?

    though i would prefer staying with sdk 16 for now and solv it but i am late on this project and pulled to other projects every few days so .. hopefuly you can help me with that

    best regards

    Ziv

  • Hello Ziv,

    Could you do an error check on the return value of the ble_advertising_advdata_update call?
    When you do not check the error code, you will not be made aware if the function fails - you should always check the returned error code.
    When checking the return value, are you getting any errors?
    Remember to define DEBUG in your preprocessor defines, to see the error output message in the log.

    Also, by calling ble_advdata_encode twice with the same destination you will override the data placed there by the first function upon return of the second function call.
    I would ask you to try this again, but this time - for simplicity - really differentiate the two buffers you are keeping. I.e separate them by name, to make things easier. Ideally, have zero overlap between the two namespaces and usage.

    ziv123 said:
    it will be best if we would find out why this is not working but i wonder if it will not be easier to just download sdk 17, maybe there is such an example working in that sdk, of updating message data while advertising ?

    There is unfortunately not such an example in the SDK 17, but using the _advdata_update function will be straight forward there - no need to keep two buffers.
    In essence, you can then just call the function with the updated advertising data, and have the new data begin advertising.
    You could modify the beacon example in SDK 17 to do this, to see for yourself how it is to use.

    ziv123 said:
    though i would prefer staying with sdk 16 for now and solv it but i am late on this project and pulled to other projects every few days so .. hopefuly you can help me with that

    I too hope that my above suggestions helps resolve this issue.

    Best regards,
    Karl

  • hi Karl 

    well it returns an error from here:

    if (p_advertising->initialized == false)
        {
            return NRF_ERROR_INVALID_STATE;
        }

    and indeed i did not initialize the :

    ble_advertising_t ble_adv;

    i asked about it before and then i didn't do it eventually.. but now after going over the links you sent, i am not sure what values should be in the second parameter of the init function:

    ble_advertising_init(&ble_adv, ???);

    may be you can help me understand the datasheet better ?

    best regards

    Ziv

  • Hello Ziv,

    ziv123 said:

    ble_advertising_init(&ble_adv, ???);

    may be you can help me understand the datasheet better ?

    The ble_advertising_init API Reference details what the second parameter must be, for the call to be successful. In essence, the second parameter is a ble_advertising_init_t struct, which contains all the information the module needs to start advertising, including config, event- and error-handler.

    Please let me know if there is anything in particular which is unclear in the documentation so I may explain.

    Best regards,
    Karl

Related