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,

    Thank you for your patience and understanding.

    ziv123 said:
    I have started working with the Laird BL654 dongle (its easier to start, just plug to the pc and connect via serial port) the plane is to work with AT command, though I am not sure yet that I can do all what I need without programing it and if I need to program it and AT commands will not be sufficient then maybe I will go back to the nrf52840 dongle (I have both dongles with me).

    I understand, thank you for letting me know. Just to be sure, when you say AT commands are you in fact referring to the SoftDevice's API through the connectivity firmware on the dongles?

    ziv123 said:
    Since in the second stage I need to be receiving status from the 100 (or 50 , not decided yet) field units then, I don't think the beacon idea will work though maybe I can use beacon and then do some pairing with the 100/50 units for the status (don't know the frequency of status returns yet as well)

    Without knowing the size of the data that needs to be transmitted, and the frequency of the transmits ( along with the number of devices and the importance of receiving every message) it is very hard to make any recommendations here. However, I too think that the beacon idea might wane when I now know more about your project.

    ziv123 said:
    I was thinking of using kind of a tree structure where the pc through the dongle sends data to 10 middle units and each of this middle units communicates with 10 different field units, send data and receive status which is then transmitted back to the dongle and the pc.

    Yes, this might very well work. Again, the performance will depend on the size of the transfers, and their frequency, but I was thinking the same thing when you described your setup in your previous comment.

    ziv123 said:
    I don't know how exactly I maintain connection with 10 specific units (to avoid 2 middle units connecting with same field unit), is it by hard coded mac addresses or is there a different way to maintain pairing with specific units.

    You can use a whitelist to ensure that the devices only connects to certain other devices.

    ziv123 said:
    (maybe it’s a basic question but I am still green with all the Gatt Gap and how Bluetooth and ble actually work when working with multiple connections)

    No problem at all, just ask if there is something you think is unclear or if you have any questions :) 

    ziv123 said:
    I don't know if AT commands alone can set the dongle to send a serial message whenever a ble of status is received since I believe it's an a-synchronic event, so if you have an idea about that I would love to read ?

    I will need to know the clarification about your meaning of AT commands from my previous question to answer this precisely, but you may program you dongle to perform a certain action when it receives a notification, if that is what you are asking.

    ziv123 said:
    Also, if you think there is a better solution then the tree structure ?

    Since you are not interested in using mesh due to the latency, then it sounds like the proposed tree-structure might be a good fit for your project. You could for example use something like the experimental relay examples between the leafs and the central device.

    ziv123 said:
    One other issue I am thinking of is that I don't have an energy issue

    On the contrary, this does not sound like an issue at all! This is usually a massive constraints for projects, so it is good that you do not have to deal with it.

    ziv123 said:
    So maybe its better to work with Bluetooth and not ble but all the examples and posts are related to ble so I don't know if there is enough data and support on Bluetooth, what would you suggest ?

    By this, do you mean Bluetooth classic? I would not image that Bluetooth classic could be a fitting option for your project, but I personally do not have a lot of experience working with Bluetooth classic.
    Just in case, I will also mention that none of our product use Bluetooth Classic - they are all BLE.
    With the information you have provided about the project it sounds like a good fit for BLE.

    ziv123 said:
    one last thing, if you can suggest examples for the tree structure or bluetooth or if you suggest something else :)

     I would recommend taking a look at the experimental relay example, and see if you think this could be used as the relay between your tree leafs and the central unit.

    As mentioned, it is hard for me to be more precise in my answers without knowing more about the size and frequency of the communication between the leafs and the central. It would also be helpful to know the importance of receiving every message from the central and peripherals.

    Looking forward to resolving this together!

    Best regards,
    Karl

  • hi Karl

    i am jumping a little bit from one question to another, sorry for that but i finely talked with directly with the client and i have some questions:

    1. if i work with a beacon, what's the safe interval in which a 31 byte message can be transfered, how much time for receiving and how much time till the next time i can send the message? same wuestion for a 255 byte of data message ? 

    i read somewhere that i can send a message every 20 ms but when i checked it with a scope it was not very stable.. i think we talked about it before actually but i am not sure.. need to look

    2. if want to create a connection with lets say 20 units, how much time from when the message is advertised till connection is established with a unit and how much time from a data message is sent to the ACK received from the field unit ? also, how much time from data message sent to the field unit till i can send the next data message to that unit

    i would also like to understand if possible what is the meaning of nrf52840 maintaining 20 connections.. does it mean it keeps a live connection with all 20 units how much time will it take to send a message to all units ?

    one more thing, if i use a different device with larger antenna will it help to get more stable and sure communication, how will it benefit the communication with the units ? 

    one more, can a device be in a scan mode for beacon from other device and advertise its own beacon at the same time ? or do i have to stop advertising -> go to scan and then back to advertise ?

    best regards

    Ziv

  • Hello Ziv,

    ziv123 said:
    i am jumping a little bit from one question to another, sorry for that but i finely talked with directly with the client and i have some questions

    No problem. However, in order to keep the forum tidy I would ask that you create a new ticket if you should have any followup questions to this comment, since the questions now have diverged from the original "beacon advertising interval" ticket questions.

    ziv123 said:
    1. if i work with a beacon, what's the safe interval in which a 31 byte message can be transfered, how much time for receiving and how much time till the next time i can send the message? same wuestion for a 255 byte of data message ? 

    The minimum advertising interval that you may configure is as mentioned 20 ms. In addition, there will be added a random 0 - 10 ms delay on top of this, which means that the worst case if 30 ms between every advertisement. These requirements are the same for the 255 byte message ( assuming you are referring to extended advertising here ).
    To see how long time different sized payloads take to transfer, please have a look at our online power profiler for the nrf52 series.
    As you can see from the online power profiler a non-connectable advertisement of 31 bytes will take 376 us to complete for each advertising channel.

    ziv123 said:
    i read somewhere that i can send a message every 20 ms but when i checked it with a scope it was not very stable.. i think we talked about it before actually but i am not sure.. need to look

    Yes, we have already spoken about this. The reason why this is not stable is the 0 - 10 ms randomly added delay. The delay is part of the BLE specification and can not be omitted.

    ziv123 said:

    2. if want to create a connection with lets say 20 units, how much time from when the message is advertised till connection is established with a unit and how much time from a data message is sent to the ACK received from the field unit ? also, how much time from data message sent to the field unit till i can send the next data message to that unit

    i would also like to understand if possible what is the meaning of nrf52840 maintaining 20 connections.. does it mean it keeps a live connection with all 20 units how much time will it take to send a message to all units ?



    You may indeed hold up to 20 concurrent connections. Please see this ticket for more detail.
    You can use the online power profiler to see how long each transfer will take, depending on the size of the transmission.
    The time till first ACK from an advertisement is hard to estimate precisely since it depends on a lot of factors, but please see this ticket for a discussion of the time to establish a connection.

    ziv123 said:
    one more thing, if i use a different device with larger antenna will it help to get more stable and sure communication, how will it benefit the communication with the units ? 

    A larger / higher power antenna will decrease the chance of packet loss, which in turn may speed up data transfer.
    The necessity of this will depend on the environment / conditions your devices are in. If there is a lot of obstacles and interference, etc.

    ziv123 said:
    one more, can a device be in a scan mode for beacon from other device and advertise its own beacon at the same time ? or do i have to stop advertising -> go to scan and then back to advertise ?

    Are you asking if a device can alternate between being a central and a peripheral?
    If so, the answer is yes. This is demonstrated in the experimental multirole examples in the SDK that I mentioned earlier.

    Best regards,
    Karl

  • hi Karl 

    My apologies, I should have written out the entire function name - ble_advertising_advdata_update.

    when writing this function in the app_ble_beacon example i get undefined reference error 

    may be you know why ?

    best regards

    Ziv

  • Hello Ziv,

    ziv123 said:
    when writing this function in the app_ble_beacon example i get undefined reference error

    Please be specific about the error messages you are seeing. Is it an undefined reference error to ble_advertising.h?
    In that case, you will need to make sure that you have included ble_advertising.h and the path /SDK/components/BLE/ble_advertising in your pre-processor defines.

    If this is not the include error in question, please elaborate.

    Best regards,
    Karl

Reply
  • Hello Ziv,

    ziv123 said:
    when writing this function in the app_ble_beacon example i get undefined reference error

    Please be specific about the error messages you are seeing. Is it an undefined reference error to ble_advertising.h?
    In that case, you will need to make sure that you have included ble_advertising.h and the path /SDK/components/BLE/ble_advertising in your pre-processor defines.

    If this is not the include error in question, please elaborate.

    Best regards,
    Karl

Children
  • the argument of this function are unknown in the app_ble_example 10040, peripheral.

    " unknown type name 'ble_advertising_t'; did you mean 'ble_version_t'? "

    " implicit declaration of function 'ble_advertising_advdata_update' [-Wimplicit-function-declaration] "

    best regards

    Ziv

  • Hi Ziv,

    Again, the more specific and detailed your answers are, the easier it will be to help you resolve this issue.
    From the two lines you included in your last comment, I would recommend that you check out your SES project settings, especially the preprocessor defines. Ensure that they include the path I gave you in my previous comment. Then, check that you have added the source file to your project files, and included the header file.

    Looking forward to resolving this issue.

    Best regards,
    Karl

  • hi Karl

    the path you mentioned is in the pre compiled file

    i also copy the line cause i am not sure the pic is clear:

    c_user_include_directories="../../../config;../../../../../../components;../../../../../../components/ble/ble_advertising;

    so its not that or maybe it needs to be called from some other place ?

    also added the following:

    <file file_name="../../../../../../components/ble/ble_advertising.c" />

    still same result 

    best regards

    Ziv

  • Hello Ziv,

    ziv123 said:
    so its not that or maybe it needs to be called from some other place ?

    Yes, it seems the paths are added correctly. How did you go about adding the paths by the way, did you insert them into this file directly? Could you also specify the exact name of the file you now have copied snippets from?

    Are you working with armgcc and Makefiles directly, or are you using an IDE like Segger Embedded Studios?
    If I know this then I can provide more detailed instructions on how to add paths and source files to your 
    Just to make sure - have you made sure to include ble_advertising.h in your main file?

    Best regards,
    Karl

  • hi Karl

    ok, there is progress, yes adding #include .. is important 

    however, the  ble_advertising.h is not called, i think, because BLE_ADVERTISING is not set

    #if NRF_MODULE_ENABLED(BLE_ADVERTISING)
    #include "ble_advdata.h"
    #include "ble_advertising.h"
    #include "nrf_soc.h"
    #include "nrf_log.h"
    #include "sdk_errors.h"
    #include "nrf_sdh_ble.h"

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

    and anyway, where is the right place to define it if that's the solution ?

    best regards

    Ziv

Related