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

Parents
  • Hello Ziv,

    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 ?

    I am not sure I follow your train of thoughts here - the lowest possible advertising interval is indeed 20 ms, but the beacon example provided in the SDK uses an advertising interval of between 100 and 200 ms, this is correct.
    The reason for this is that beacons do not usually transfer a whole lot of data, and as such it is more power efficient to not advertise with the lowest possible interval. You may of course change this in your own application, to use the 20 ms advertising interval.

    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.

    If you are using the advertising module you may instead use the _advdata_update function.
    However, the _advdata_update function has a known issue, which requires that you have two adv_data instances that you alternate between passing to update and updating.
    That is to say: you may not pass a single advdata instance to advertising start, update the same advdata instance and then provide it as the argument to _advdata_update.
    Instead, you will have to have two advdata instances, where you pass one as the argument to the _advdata_update function, and then you may update the other advdata instance, before calling _advdata_update again with the most recently updated(not currently in use) advdata instance.

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

    Advertisements are transfers without acknowledgments, and they may indeed be lost sometimes - there are no retransmissions because there is never any acknowledgements. This can happen more often if the devices are far apart, and if they are operating in a 2.4 GHz noisy environment. The time can not be completely fixed either, due to the random 10 ms delay that is added before every advertisement. This is part of the BLE specification and can not be removed.

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

    Please elaborate on the exact timings you are seeing. How are you measuring this by the way, only the toggling pin, or do you also use the BLE Sniffer tool

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

    This is possible using beacon advertisements, since with a 20 ms advertising interval your worst case will be 30 ms between each advertisement, which again means that you will get more than 30 packets per second.
    However, you will need to keep in mind that advertisement packets may be lost. This is the biggest drawback of using advertisements to transfer data, and also what makes advertisement data transfer infeasible if you need to make sure every packet is received.
    In the latter case, you will need to establish a connection to ensure that every packet is received.

    Please let me know if anything still should be unclear,
     
    Best regards,
    Karl

  • hi Karl

    good to read from you 

    the thing i actually have to design is

    1. a software for 150 units that receive data (specific for each of them) from one broadcasting unit that is connected to a pc

    2. dLL for the beacon broadcasting gateway or dongle or whatever that is connected to the pc which is running some python app (will need some help with that later)

    regarding the first part:

    • I have no power saving issues since power will be given to all units all the time
    • I was going for broadcasting and beacon to avoid making connection with each unit which i think will take a lot of time on Acks and reconnecting with a different unit every time. I would have sent one big message to all units ,if it was possible, and maybe send it multiple times in a second just to make sure every unit got it.
    • So i was toggling myself between working on an extended beacon broadcast, to checking how much data i can transfer in the 31 byte message and how many times i can transfer it ,so that if one 31 byte message can contain data for 10 units, i have to see that i can send the message to all 150 units every one second
    You may of course change this in your own application, to use the 20 ms advertising interval.

    can i also control the scan interval, and if so how and is there some issues i need to take under consideration when doing that ?

    Instead, you will have to have two advdata instances, where you pass one as the argument to the _advdata_update function, and then you may update the other advdata instance, before calling _advdata_update again with the most recently updated(not currently in use) advdata instance.

    i could not find any _advdata_update function in the ble_advdata.h file. if or when i find the function you are referring to then do i need to stop the advertising and restart it like in the following code, and update in the middle or i can only update advdata in the timer handler and the broadcasting continue in its interval ?:

    sd_ble_gap_adv_stop(m_adv_handle);
        err_code = ble_advdata_encode(&advdata, 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);

    This can happen more often if the devices are far apart, and if they are operating in a 2.4 GHz noisy environment

    if i am using the ADDRESS FILTER:

        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_ADDR_FILTER, m_target_periph_addr); // Ziv
        APP_ERROR_CHECK(err_code);
    
        // Setting filters for scanning.
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_ADDR_FILTER, false); // Ziv
        APP_ERROR_CHECK(err_code);

    does it change something regarding noises or every message from any device is received and read all the way anyway  and only then is filtered ?

    How are you measuring this by the way

    i toggle a pin in the case of ' NRF_BLE_SCAN_EVT_FILTER_MATCH '  in the ' scan_event_handler(...) '

    i look at the pin in the scope in a 50ms for each square 

    Regarding the second thing:

    if you can recommend a gateway or a device, gateway or other that connects to a pc via usb and comes with a convenient API so i can wrap it and supply the customer with an easy API for the data needed to be transferred to all the 150 units via bl, that would be great. 

    i read some about the nrf52840 dongle but someone wrote that it has a lot of over had regarding softdevice and serialization if i recall and actually recommend using a designated device (for us price of such device is not an issue)

    hope to read from you soon 

    best regards

    Ziv

  • Hello Ziv,

    ziv123 said:
    however, the  ble_advertising.h is not called, i think, because BLE_ADVERTISING is not set
    ziv123 said:
    where is the right place to define it if that's the solution ?

    That could very well be the case. If so, please check that BLE_ADVERTISING_ENABLED is defined to 1 in the sdk_config.
    Please try this, and see if the undefined reference error is resolved.

    ziv123 said:
    but again, why it would not be configured in a build in beacon example ???  

    The Beacon example from the SDK does not use the advertising library - it uses the ble_advdata library and direct calls to the SoftDevice API.

    Best regards,
    Karl 

  • hi Karl

    thanks, it compiles now 

    how ever, is there an example that uses the advertising library to get a better sense of needed configuration for the ble_advertising_t element ?

    if not, how should it be configured and will the 2 libraries work together ? 

    ... WELL i have tried to implement it but i see no change in the nrf scan app, and after looking some more to the function it's not clear to me why i need 2 instances since one is for scanned data and i am working with beacon 

    here my code, its a bit messy cause it's just to see its working , you can see the commented lines which do give change in data packets via nrf scan app

    static void data_update_timer_handler(void* p_context)
    {
        ret_code_t err_code;
        static uint8_t advdata_next_idx = 0;
    
        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_next_idx = 1;
        else if( 1 == advdata_idx)  advdata_next_idx = 0;
        advdata[advdata_idx].p_manuf_specific_data = &manuf_specific_data;
        
        advdata[advdata_next_idx] = advdata[advdata_idx];
        ble_advertising_advdata_update(&ble_adv ,&advdata[advdata_next_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;
    }
    #define EVERY_ONE_SECOND (200) // milli second
    APP_TIMER_DEF(data_change_timer);

    another thing, maybe i will open a new topic for that, regarding the nrf52840 dongle.. is it possible to program it to do the following via the nrf programmer (from the pc app):

    receive data via usb as uart and advertise it in a way that if no new data is arriving via uart the dongle keeps on advertising every 30ms (basically to receive data and update the advdata every time new data is received, or send each received mesage for several times in shortest intervals (30ms) unless new data arrives (also is it possible to program it to change some part of the data by itself each time it receives data from uart(meaning send the same data 10 times for instance, each time with one byte change in the data)

    that is instead of programming it via some development boards debugger ? 

    best regards

    Ziv

  • hopefully we can resolve this before the end of this week 

  • ?? sorry for nagging but i really need help with that and i am on a tight scheduled 

  • Hello Ziv,

    ziv123 said:
    hopefully we can resolve this before the end of this week 

    Yes, hopefully we will resolve this before the weekend.

    ziv123 said:
    thanks, it compiles now 

    That it good. Are you experiencing any unexpected behavior since switching to the advertising module?

    ziv123 said:

    how ever, is there an example that uses the advertising library to get a better sense of needed configuration for the ble_advertising_t element ?

    if not, how should it be configured and will the 2 libraries work together ?

    Unfortunately no, none of the SDK examples currently use the advertising library - however, you could take a look at the "Usage" section of the library documentation to get started. You can also see the description of each config parameter here.
    Fortunately, the advdata structure and advertising module goes well together, there is no problem at all using both.

    ziv123 said:
    ... WELL i have tried to implement it but i see no change in the nrf scan app, and after looking some more to the function it's not clear to me why i need 2 instances since one is for scanned data and i am working with beacon 

    Could you confirm for me that you are working with SDK 16, or if you have upgraded to SDK 17 since we last spoke about it?
    If you are using SDK 17 then you do not need to have two advertising data structures, you can just work with a single one.
    You do not need to provide scan response data.

    ziv123 said:
    here my code, its a bit messy cause it's just to see its working , you can see the commented lines which do give change in data packets via nrf scan app

    Are you saying that the code as you have shared it does nothing to change the advertising data, except if you include the commented part at the end?
    The advdata_update function handles the necessary encoding and configuration as well, please take a look in the advertising library source code.

    ziv123 said:

    another thing, maybe i will open a new topic for that, regarding the nrf52840 dongle.. is it possible to program it to do the following via the nrf programmer (from the pc app):

    receive data via usb as uart and advertise it in a way that if no new data is arriving via uart the dongle keeps on advertising every 30ms (basically to receive data and update the advdata every time new data is received, or send each received mesage for several times in shortest intervals (30ms) unless new data arrives (also is it possible to program it to change some part of the data by itself each time it receives data from uart(meaning send the same data 10 times for instance, each time with one byte change in the data)

    that is instead of programming it via some development boards debugger ? 

    In short; yes, this is possible. You can either program the Dongle directly as you would have programmed a DK, or you can create a desktop application using the pc-ble-driver that controls the dongle. However, please open a new ticket for this subject if you require more information about this, as it is diverging from your initial ticket.

    Best regards,
    Karl

Reply
  • Hello Ziv,

    ziv123 said:
    hopefully we can resolve this before the end of this week 

    Yes, hopefully we will resolve this before the weekend.

    ziv123 said:
    thanks, it compiles now 

    That it good. Are you experiencing any unexpected behavior since switching to the advertising module?

    ziv123 said:

    how ever, is there an example that uses the advertising library to get a better sense of needed configuration for the ble_advertising_t element ?

    if not, how should it be configured and will the 2 libraries work together ?

    Unfortunately no, none of the SDK examples currently use the advertising library - however, you could take a look at the "Usage" section of the library documentation to get started. You can also see the description of each config parameter here.
    Fortunately, the advdata structure and advertising module goes well together, there is no problem at all using both.

    ziv123 said:
    ... WELL i have tried to implement it but i see no change in the nrf scan app, and after looking some more to the function it's not clear to me why i need 2 instances since one is for scanned data and i am working with beacon 

    Could you confirm for me that you are working with SDK 16, or if you have upgraded to SDK 17 since we last spoke about it?
    If you are using SDK 17 then you do not need to have two advertising data structures, you can just work with a single one.
    You do not need to provide scan response data.

    ziv123 said:
    here my code, its a bit messy cause it's just to see its working , you can see the commented lines which do give change in data packets via nrf scan app

    Are you saying that the code as you have shared it does nothing to change the advertising data, except if you include the commented part at the end?
    The advdata_update function handles the necessary encoding and configuration as well, please take a look in the advertising library source code.

    ziv123 said:

    another thing, maybe i will open a new topic for that, regarding the nrf52840 dongle.. is it possible to program it to do the following via the nrf programmer (from the pc app):

    receive data via usb as uart and advertise it in a way that if no new data is arriving via uart the dongle keeps on advertising every 30ms (basically to receive data and update the advdata every time new data is received, or send each received mesage for several times in shortest intervals (30ms) unless new data arrives (also is it possible to program it to change some part of the data by itself each time it receives data from uart(meaning send the same data 10 times for instance, each time with one byte change in the data)

    that is instead of programming it via some development boards debugger ? 

    In short; yes, this is possible. You can either program the Dongle directly as you would have programmed a DK, or you can create a desktop application using the pc-ble-driver that controls the dongle. However, please open a new ticket for this subject if you require more information about this, as it is diverging from your initial ticket.

    Best regards,
    Karl

Children
  • hi Karl

    Could you confirm for me that you are working with SDK 16

    yes, i checked the zip file i downloaded, and working with -> "nRF5_SDK_16.0.0_98a08e2.zip"

    Are you saying that the code as you have shared it does nothing to change the advertising data, except if you include the commented part at the end?

    YES, when using the commented lines instead of the advdata_update function then i see change in data in the nrf_connect_app on my cell phone. but when i am using the function as shown in the code i added i don't see a change in the data in the same app on my cell phone

    i will open a new topic on the dongle issue

    hope to read from you soon

    best regards

    Ziv

Related