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

Current solution to update packets while advertising for every packet

Hi,

I have seen this post, but it is quite old, so I would like to know what is the current solution to

  • update advertising packets while advertising, without stop and start again the transmission
  • update some bytes in my manufacturer data
  • update my packet for each new packet that i send.

I am currently using the ble_advertising library, with a NRF52 BLE kit on Eclipse. 

  • static void Update_data(void)
    {
    	ret_code_t err_code;
    	ble_gap_adv_data_t adv_data;
    	uint8_t data[2];
    
    	if(counter>255) counter = 0;
    	m_beacon_info[0] = (uint8_t)counter;
    	counter++;
    
    	adv_data.adv_data.p_data = m_beacon_info;
    	adv_data.adv_data.len = sizeof(m_beacon_info);
    
    	err_code = ble_advertising_advdata_update(&m_advertising, &adv_data, true);
    	APP_ERROR_CHECK(err_code);
    
    }

    I have tried to use the ble_advertising_advdata_update(), but when i have flashed it on my BLE kit, I cannot see my device anymore with my phone. 

  • Hello,

    It sounds to me like the ble_advertising_advdata_update() indeed is what you are looking for - it allows you to update the advertising data as you go.

    Beldramma said:
    I have tried to use the ble_advertising_advdata_update(), but when i have flashed it on my BLE kit, I cannot see my device anymore with my phone. 

    Are you getting any error, or indications that the device has failed somewhere?
    According to the functions documentation the function should return one of the three possibilities: NRF_SUCCESS, NRF_ERROR_NULL or NRF_ERROR_INVALID_STATE. Could you check to see that you are receiving the NRF_SUCCESS?

    Furthermore, I see that your function call passes "true" to the updated scan response data field.. Why do you do this? I do not think this will work since the function expects a ble_advdata_t struct, or a NULL pointer.

    Best regards,
    Karl

  • So I have the '9' value error code, I don't know what it means. Btw, if you can tell me how I can see the error message from the APP_ERROR_CHECK, it will be nice.

    Also, i have observed than when I flash the program on my kit, for the first 100 milliseconds I can observe my program but after it disappears.

    I also read this post ,it seems that the ble_advertising_advdata_update is not really working. Have you already used this function ?

    Best regards,

  • I understood why I put true: it's because I used the SDK15 ble_advertising function. I replaced it by the one from the SDK16. 

    Here is my current code : 

    static void Update_data(void)
    {
    	//AKR
    	ret_code_t err_code;
    	ble_advdata_t advdata;
    	ble_advdata_manuf_data_t manuf_specific_data;
    	//AKR
    
    	if(counter>255) counter = 0;
    	m_beacon_info[0] = (uint8_t)counter;
    	counter++;
    
        memset(&advdata, 0, sizeof(advdata));
    
        advdata.name_type               = BLE_ADVDATA_FULL_NAME;
        advdata.include_appearance      = false; //AKR
        // adv manuf specific data //AKR
        manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
        manuf_specific_data.data.p_data = m_beacon_info;
        manuf_specific_data.data.size   = APP_BEACON_INFO_LENGTH;
        advdata.p_manuf_specific_data   = &manuf_specific_data;
    
    	err_code = ble_advertising_advdata_update(&m_advertising, &advdata, NULL);
    
    	APP_ERROR_CHECK(err_code);
    
    }

    APP_BEACON_INFO_LENGTH = 13

    m_beacon_info is a uint8_t table with 13 boxes. 

    Now my device is always is always visible, but my advdata is not updating. In debug mode, I can see the error code NRF_ERROR_INVALID_ADDR  (16), don't know why yet. 

  • Hi again,

    Beldramma said:
    I understood why I put true: it's because I used the SDK15 ble_advertising function. I replaced it by the one from the SDK16. 

     Are you currently working with SDK v.15 or SDK v.16? You will need to read the function documentation with the right version number.

    Beldramma said:

    APP_BEACON_INFO_LENGTH = 13

    m_beacon_info is a uint8_t table with 13 boxes. 

    So the beacon info is an uint8_t array with length 13.

    Beldramma said:
    Now my device is always is always visible, but my advdata is not updating. In debug mode, I can see the error code NRF_ERROR_INVALID_ADDR  (16), don't know why yet. 

    I suspect that you may be attempting to squeeze more than 31 bytes into your advdata, which causes the advdata_update to fail. Could you verify the length of your entire advertising data?

    How long is your device name? Keep in mind that the maximal advertisement length is 31 bytes, and every data field requires two bytes overhead(length and type). You will also need a FLAG data field, which uses 3 bytes of the 31 available, effectively leaving you at 28 remaining bytes. If the beacon_info is 13 bytes long, with 2 byte overhead, then you have 13 bytes left. So, if your device name is longer than 11 bytes, you will run out of space.

    Are you familiar with using the nRF Sniffer tool? It could be useful to see a sniffer trace of the BLE communication happening, in order to know exactly what is being advertised.

    Beldramma said:
    So I have the '9' value error code, I don't know what it means. Btw, if you can tell me how I can see the error message from the APP_ERROR_CHECK, it will be nice.

    If you are using logging you could just log the error code to see it.

    Beldramma said:
    Also, i have observed than when I flash the program on my kit, for the first 100 milliseconds I can observe my program but after it disappears.

    What do you mean by this, do you mean that the device only advertises the first 100 ms?
    Could you check what you advertising timeout is set to? And make sure that the device is still running(not crashed) after 100 ms?
    This could for example be verified using the nRF Sniffer I mentioned above.


    Best regards,
    Karl  

Related