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. 

Parents
  • 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

  • Hi Karl. Well, with my program, I cannot check which version it is for now, but I think that I am on SDK 15. I I have decided to evolve from SDK15 to 16 because it seems to me that the ble_advertising_advdata_update is not working on SDK15. I have begun, but for now, I have a lot of mistakes. Is this function working on SDK15 ? 

  • Ok, so finally I am working with SDK15. My function is working well: 

    static void Update_data(void)
    {
    	ret_code_t err_code;
    	ble_advdata_manuf_data_t manuf_specific_data;
    	ble_advdata_t advdata;
    
    	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;
    
        //Encoding of the data to be updated after
        err_code = ble_advdata_encode(&advdata, m_advertising.adv_data.adv_data.p_data, &m_advertising.adv_data.adv_data.len);
        APP_ERROR_CHECK(err_code);
    
        //Updating of the encoded data
    	err_code = ble_advertising_advdata_update(&m_advertising, &m_advertising.adv_data, true);
    	APP_ERROR_CHECK(err_code);
    
    }
    

    To easily use the ble_advertising_advdata,update from SDK15, I have used the ble_encode function. Now I can see that my frames are updated with the NRF sniffer app tool. What I want now, is to update my frame for each frame that I send. Do youknow how can I do that ?

  • Hello again,

    Beldramma said:
    I have decided to evolve from SDK15 to 16
    Beldramma said:
    Ok, so finally I am working with SDK15.

    Did you here mean to say that you finally is working with SDK 16, or have I misunderstood you? 
    Keep in mind that the advdata_update function was introduced in SDK v.15.2.0, and is not present in < v.15.2.0.

    Beldramma said:
    To easily use the ble_advertising_advdata,update from SDK15, I have used the ble_encode function.

    You should not have to encode the data prior to sending it to the advdata_update function, since that is done within the update function itself. Are you saying that the advdata_function did not work as expected, until you provided it with already encoded advdata?

    Beldramma said:
    Now I can see that my frames are updated with the NRF sniffer app tool.

    I am happy that your advertising is behaving as expected!

    Beldramma said:
    What I want now, is to update my frame for each frame that I send. Do youknow how can I do that ?

    To do this you would have to call the update function with new data every time an advertisment is made.
    Be advised that packets may be corrupted or lost on the way depending on the environment, so if you are only advertising some data once, certain datapoints may never reach the central.

    Best regards,
    Karl

  • Did you here mean to say that you finally is working with SDK 16, or have I misunderstood you? 
    Keep in mind that the advdata_update function was introduced in SDK v.15.2.0, and is not present in < v.15.2.0.

    No I am working on SDK 15.2. So I have the first version of the ble_advertising_advdata_update, and I need to encode the data myself. 

    To do this you would have to call the update function with new data every time an advertisment is made.
    Be advised that packets may be corrupted or lost on the way depending on the environment, so if you are only advertising some data once, certain datapoints may never reach the central.

    Do you know how to do that ? I am trying to use the ble_radio_notification_init to update my data each time. Theorically, after each new sending, this interruption will be activated and will call an function that here is Radio_handler. I am using it, but it seems to me that it doesn't work very well, because I have not oonly one incrementation of my byte between each packet but few incrementations. 

    Here is my code : 

    void Radio_handler(bool radio_evt)
    {
        if (radio_evt)
        {
            Update_data(); //Toggle the status of the LED on each radio notification event
        }
    }
    void radio_notification_handler_init(void)
    {
    	ret_code_t err_code;
    	err_code = ble_radio_notification_init(APP_IRQ_PRIORITY_LOW, NRF_RADIO_NOTIFICATION_DISTANCE_5500US, Radio_handler);
    	APP_ERROR_CHECK(err_code);
    }

    I don't know what is the problem for now.

  • Hello again,

    Beldramma said:
    No I am working on SDK 15.2. So I have the first version of the ble_advertising_advdata_update, and I need to encode the data myself. 

    Yes, my mistake. I was checking the source code of the SDK v.16, I see now that you must call encode before calling the SDK v.15.2 advdata_update version, my apologies for any confusion this might have caused.

    Beldramma said:
    Do you know how to do that ? I am trying to use the ble_radio_notification_init to update my data each time. Theorically, after each new sending, this interruption will be activated and will call an function that here is Radio_handler. I am using it, but it seems to me that it doesn't work very well, because I have not oonly one incrementation of my byte between each packet but few incrementations. 

    For this you will need radio notifications, for further detail on this please see my colleagues reply to this ticket.

    Let me know if anything should still be unclear!

    Best regards,
    Karl

Reply
  • Hello again,

    Beldramma said:
    No I am working on SDK 15.2. So I have the first version of the ble_advertising_advdata_update, and I need to encode the data myself. 

    Yes, my mistake. I was checking the source code of the SDK v.16, I see now that you must call encode before calling the SDK v.15.2 advdata_update version, my apologies for any confusion this might have caused.

    Beldramma said:
    Do you know how to do that ? I am trying to use the ble_radio_notification_init to update my data each time. Theorically, after each new sending, this interruption will be activated and will call an function that here is Radio_handler. I am using it, but it seems to me that it doesn't work very well, because I have not oonly one incrementation of my byte between each packet but few incrementations. 

    For this you will need radio notifications, for further detail on this please see my colleagues reply to this ticket.

    Let me know if anything should still be unclear!

    Best regards,
    Karl

Children
  • Yes, my mistake. I was checking the source code of the SDK v.16, I see now that you must call encode before calling the SDK v.15.2 advdata_update version, my apologies for any confusion this might have caused.

    Don'tworry, all was clear.

    For this you will need radio notifications, for further detail on this please see my colleagues reply to this ticket.

    I have checked it, but we do not need to call sd_radio_notification_cfg_set function anymore, it is called in the ble_radio_notification_init function. 

    It seems that it is working, but with my sniffers, I do not have all the frames, I miss some of them. I would like to check if it is because my sniffers cannot have all of them, or if it is because i do not send all of them. Do you have an idea how I can check which frames do I send ?

  • Beldramma said:
    Don'tworry, all was clear.

    I am happy to hear that!

    Beldramma said:

    I have checked it, but we do not need to call sd_radio_notification_cfg_set function anymore, it is called in the ble_radio_notification_init function. 

    It seems that it is working, but with my sniffers, I do not have all the frames, I miss some of them. I would like to check if it is because my sniffers cannot have all of them, or if it is because i do not send all of them. Do you have an idea how I can check which frames do I send ?

    Yes, this could be the case - that the sniffer is missing some that the central is receiving, and vice verse.
    To check that the amount of frames sent, you could add a counter that increments for each advertisement - and then match this against what you would have expected/what you received on your central's end.
    If you would like to see the frames sent in particular, you could use deferred logging to do the processing post-sending, I.e sending a certain amount of frames while logging their contents - then processing the deferred logs once a certain amount has been sent.
    Would this be along the lines you were thinking?

    Best regards,
    Karl 

Related