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

  • hi Karl

    i guess i am doing something wrong cause the ble_advertising_init(..) falls in here:

     ret = sd_ble_gap_adv_set_configure(&p_advertising->adv_handle, NULL, &p_advertising->adv_params);
        VERIFY_SUCCESS(ret);
    

    the ret = 7, error, i can not find what goes in the sd_ble_gap_adv_set_configure(..) 

    also, it is not clear to me if i need to also use the 

    static void advertising_init(void) 

    and inside it call the ble_advertising_init(..) cause it seems there is and advdata initialization with in it

    anyway .. this is what i have tried

    static void advertising_init(void)
    {
        uint32_t      err_code;
        //ble_advdata_t advdata;
        uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
    
        //ble_adv_modes_config_t ble_adv_mode = true;
        //ble_advdata_manuf_data_t manuf_specific_data;
        ble_adv_init.config.ble_adv_fast_enabled = true;
    
        ble_adv_init.advdata.flags = flags;
        ble_adv_init.advdata.name_type = BLE_ADVDATA_NO_NAME;
        ble_adv_init.advdata.p_manuf_specific_data = &manuf_specific_data;
    
        //ble_adv_init.srdata = NULL;
        ble_adv_init.error_handler = NULL;
        ble_adv_init.evt_handler = NULL;
    
        ble_advertising_init(&ble_adv, &ble_adv_init);
        manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
    
    #if defined(USE_UICR_FOR_MAJ_MIN_VALUES)
        // If USE_UICR_FOR_MAJ_MIN_VALUES is defined, the major and minor values will be read from the
        // UICR instead of using the default values. The major and minor values obtained from the UICR
        // are encoded into advertising data in big endian order (MSB First).
        // To set the UICR used by this example to a desired value, write to the address 0x10001080
        // using the nrfjprog tool. The command to be used is as follows.
        // nrfjprog --snr <Segger-chip-Serial-Number> --memwr 0x10001080 --val <your major/minor value>
        // For example, for a major value and minor value of 0xabcd and 0x0102 respectively, the
        // the following command should be used.
        // nrfjprog --snr <Segger-chip-Serial-Number> --memwr 0x10001080 --val 0xabcd0102
        uint16_t major_value = ((*(uint32_t *)UICR_ADDRESS) & 0xFFFF0000) >> 16;
        uint16_t minor_value = ((*(uint32_t *)UICR_ADDRESS) & 0x0000FFFF);
    
        uint8_t index = MAJ_VAL_OFFSET_IN_BEACON_INFO;
    
        m_beacon_info[index++] = MSB_16(major_value);
        m_beacon_info[index++] = LSB_16(major_value);
    
        m_beacon_info[index++] = MSB_16(minor_value);
        m_beacon_info[index++] = LSB_16(minor_value);
    #endif
    
    ///ziv addition:
      //  static uint8_t i = 4;
      //  if( i >= SET_VALUES_ARRAY )
      //  {
      //      i = 0;
      //  }
       // uint8_t idx = i++;
       m_beacon_info[12] = spin_angle[3];
       m_beacon_info[13] = (spin_direction[3] | speed[3]);
    
    // ziv addition end  
    
        manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info;
        manuf_specific_data.data.size   = APP_BEACON_INFO_LENGTH;
    
        // Build and set advertising data.
        memset(&advdata_1, 0, sizeof(advdata_1));
        memset(&advdata_2, 0, sizeof(advdata_2));
    
        advdata_1.name_type        = BLE_ADVDATA_NO_NAME;//BLE_ADVDATA_SHORT_NAME;//BLE_ADVDATA_NO_NAME;
        advdata_2.name_type        = BLE_ADVDATA_NO_NAME;
        advdata_1.flags            = flags;
        advdata_2.flags            = flags;
        advdata_1.p_manuf_specific_data = &manuf_specific_data;
        advdata_2.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_1, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
        APP_ERROR_CHECK(err_code);
        err_code = ble_advdata_encode(&advdata_2, 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);
    }
    

    hope you can tell me what i am doing wrong ???

    best regards

    Ziv

  • hi Karl

    another question on this matter, once we solve this, is there a way to update/change the advdata every time there is an advertise? meaning ,if advertising interval is 30ms, then after every transmit the advdata will change according to some handler without using a timer to call the advdata_update function ?

     best regards

    Ziv

  • it strange but when using the regular advertising_init() without using the ble_advertising_init(), and setting the timer to change only the ble_advdata_encode() like this:

    advdata_1.p_manuf_specific_data = &manuf_specific_data;
    //    err_code = sd_ble_gap_adv_stop(m_adv_handle);
    //    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_uart_put(err_code);
        APP_ERROR_CHECK(err_code);

    without stopping and starting the advertising, then it seems to be working and changing.. i am not sure if it is a risky and unstable way and ii cant realy use the nrf app for testing it with advertising interval less then 500ms

    what do you think of that ?

    and also would appreciate answering the other 2 reply's :)  

    best regards

    Ziv

  • Hello Ziv,

    ziv123 said:
    i guess i am doing something wrong cause the ble_advertising_init(..) falls in here:

    Just in case I will mention that you are calling the init with no advertising data, please see the sd_ble_gap_adv_set_configure API Reference.

    ziv123 said:
    the ret = 7, error, i can not find what goes in the sd_ble_gap_adv_set_configure(..) 

    Have you defined DEBUG in your preprocessor defines?
    In that case, please use APP_ERROR_CHECK instead of VERIFY_SUCCESS - verify_success only check whether the passed argument is NRF_SUCCESS and if not it only returns the error code. APP_ERROR_CHECK calls the error event handler in the case that the error code is not NRF_SUCCESS. In the default case, we will then know what caused the error by looking in the log.
    You can define DEBUG in Segger Embedded Studios as shown in the included picture:

    ziv123 said:

    static void advertising_init(void) 

    and inside it call the ble_advertising_init(..) cause it seems there is and advdata initialization with in it

    I do not understand what you mean by this. ble_advertising_init is the init function for the Advertising Module. The general advertising_init function is doing more than just calling ble_advertising_init.

    ziv123 said:
    hope you can tell me what i am doing wrong ???

    Please call APP_ERROR_CHECK, with DEBUG defined, on the error code, so we may know which error is generated, and where it is generated.
    This will make debugging much easier. I suspect that you are providing an invalid argument to a function, or similar - this will easily be seen with the DEBUG define and APP_ERROR_CHECK.
    Furthermore, you should really always call APP_ERROR_CHECK on your functions that may return non-successfully, to ensure that you are made aware of their failing - and that you may handle it accordingly.

    ziv123 said:
    another question on this matter, once we solve this, is there a way to update/change the advdata every time there is an advertise? meaning ,if advertising interval is 30ms, then after every transmit the advdata will change according to some handler without using a timer to call the advdata_update function ?

    Yes, this is possible, as we have spoken about earlier. You will have to do this using Radio Notifications. Please see this ticket for further information.
    However, I must again mention that it is not guaranteed that advertisements are received by the other devices, so by transmitting data using advertisements you must anticipate some packet loss. There is also no retransmission on advertisements, so this might mean that your advertisement never is hear, and the data is lost - without any feedback.
    Based on your previous comments I am inclined to think that packet loss might be an issue in your project, and you might therefore want to send the advertisements multiple times, to increase the chance that they are received successfully.

    ziv123 said:

    without stopping and starting the advertising, then it seems to be working and changing.. i am not sure if it is a risky and unstable way and ii cant realy use the nrf app for testing it with advertising interval less then 500ms

    what do you think of that ?



    If you would like to monitor the BLE Traffic ( advertisements ) more closely, I highly recommend using the nRF Sniffer tool. It lets you see all advertisements and BLE communication that the Sniffer is able to intercept. It is a very powerful tool when developing with BLE.

    I am not sure that I understand you setup here. Do you mean that you have a timer that calls the _encode periodically?
    Have you abandoned the idea of using the _advdata_update function?

    Best regards,
    Karl

  • hi Karl 

    the radio library you are talking about, i could not find it in the sdk 16.0, the branch is empty 

    am i missing something ?

    best regards

    Ziv

Related