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

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

Children
  • Hello Ziv,

    I understand. That is a lot of units to control, but if you are broadcasting an instruction then all the devices within range will indeed get the advertisement, no problem.
    I would recommend sending it multiple times, to increase the probability that every other unit receives the advertisement.
    The longer the advertisement, the bigger the chance of it being affected 

    ziv123 said:
    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 ?

    Yes, you may change the scan interval too.
    The scan interval should be at minimum advertising interval + 10 ms. Increasing scan interval might allow you to receive more packets, but it will require more power.

    ziv123 said:
    i could not find any _advdata_update function in the ble_advdata.h file.

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

    ziv123 said:
    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

    If you are using the ble_advertising_advdata_update function then you do not need to stop, update and start advertising again. Then you may only call the _advdata_update function as part of your timer callback, yes. However, keep in mind the double advdata instance you will need to keep alternating between, like I explained in my previous comment.
    If you do not do this, then the ble_advertising_advdata_update function will not work.

    ziv123 said:
    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 ?

    Unfortunately, filters does nothing to improve on interference from 2.4 GHz noise in the environment.
    You are correct that every message is received and read, and then the filters are applied after that.

    ziv123 said:
    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. 

    The nRF52840 dongle is well suited for this.
    You might want to take a look at the pc-ble-driver when you are going to work on this device.

    ziv123 said:
    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)

    I do not understand what you mean by that the nRF52840 dongle is not a designated device, please elaborate.
    The device ( regardless of if it is a dongle or not ) will need a BLE stack either way to be able to communicate using BLE - the SoftDevice is a great and convenient BLE stack implementation that is readily available for all Nordic products.

    Best regards,
    Karl

  • hi Karl

    I would recommend sending it multiple times, to increase the probability that every other unit receives the advertisement.

    that was my plan though in one 31 bytes packet i can have a data for 10 units, so i need to broadcast at least 15 messages like this in a second and preferably at least 2 times for each message -> 30 messages per second, i know that in theory i can broadcast every 20ms and that should be enough but from checking in the scope on the pin toggle i saw it was less stable in those intervals (we discussed this already i think) 

    Unfortunately, filters does nothing to improve on interference from 2.4 GHz noise in the environment.
    You are correct that every message is received and read, and then the filters are applied after that.

    what about whitelist ? does it work better, if i want all units to read only from a certain address ? if so, how is it done on both sides ?

    The nRF52840 dongle is well suited for this.

    It is not clear to me if i can use the dongle nrf52840 as it is without programing it, just sending serial data and have some AT command list that i can operate it through that. So at the moment i am wondering if i should use a bll654 (it has a nrf52840 soc) which comes programed already and no special installations are required (it is more expensive i know), but i don't know to what extent i can control it through the AT commands, like setting broadcast intervals and use of all the 31 bytes of data to my needs without having fixed big headers... or if i use the nrf52840 dongle and program it and download all necessary dependencies, softdevice and more stuff that i briefly saw in the github link you add  

    so, anyway, at the moment i am starting to work on writing a python app that will identify one of this usbs and send serial data to it (for haps there is already a written code for that in the softdevice for the nrf52840 dongle, i don't know) 

    so any advice on that matter will be helpful and maybe i would make a better decision on where to invest until the dongles arrive :)

    best regards

    Ziv

  • hi Karl

    hope all is all right cause you kind of vanished 

    anyway .. i still have all the questions i posted but i also need to think on another metter:

    till now the project was to send data from one unit to 150 units in the area and beacon can solve this, 

    but now, i also need to transfer data back from the 150 units to the device connected to the pc, and that seams to be a little bit more complicated .. 

    can you advice on that matter? what are the options, cons and prunes ?

    best regards

    Ziv

  • Hello again Ziv,

    I am terribly sorry for my late reply - I have been out of office for some time now. My apologies.

    ziv123 said:
    preferably at least 2 times for each message

    This depends on what environment you are in - how much noise / interference you will have, and the distance between units, line-of-sight etc.
    If it is important that as many advertisements as possible is received, then you should transfer the advertising more than just 2 times.

    ziv123 said:
    i know that in theory i can broadcast every 20ms and that should be enough but from checking in the scope on the pin toggle i saw it was less stable in those intervals (we discussed this already i think) 

    Please tell me what you mean that it is less stable in those intervals.

    ziv123 said:
    what about whitelist ? does it work better, if i want all units to read only from a certain address ? if so, how is it done on both sides ?

    No, the whitelist does nothing to improve environment noise - it only determines which units may establish a connection with the device. If you want your units to only read from a certain address you should add a filter, and then use the filter match event to process the received data, instead of the advertising report.
    When you are using filters you will still see the non-filtered advertisements in the advertisement reports, which is why you should use filters to filter out only the ones of interest.

    ziv123 said:
    It is not clear to me if i can use the dongle nrf52840 as it is without programing it

    I am not sure what you mean by this - the dongle will need to be programmed in order to perform any function. You will need to program the dongle with the connectivity firmware, as described in the readme, to use the pc-ble-driver I referenced in my last reply. Please see the "Programming Connectivity HEX files" section of the github readme.

    ziv123 said:

    so, anyway, at the moment i am starting to work on writing a python app that will identify one of this usbs and send serial data to it (for haps there is already a written code for that in the softdevice for the nrf52840 dongle, i don't know) 

    so any advice on that matter will be helpful and maybe i would make a better decision on where to invest until the dongles arrive :)

    Have you received your dongles yet? It sounds to me like the pc-ble-driver directly is what you are looking to use here. If I understand you correctly that you would like to write the application in python, please instead have a look at the pc-ble-driver-py.
    If you follow the readme to setup your dongles, you may then access the softdevice API directly using the driver.

    ziv123 said:

    but now, i also need to transfer data back from the 150 units to the device connected to the pc, and that seams to be a little bit more complicated .. 

    can you advice on that matter? what are the options, cons and prunes ?

    This is a major change to the project, as I had understood it. It is definitely more complicated to create a all-to-one network.
    How much data is being transferred, and how often does it need to be transferred? You might have to look into either establishing connections to different groups of devices, or look into using the mesh network structure to resolve this - based on the answers to my question above.

    Could you also tell me how these 150 peripheral devices are arranged, in regards to distance between each other? Are they all evenly spread out over an area, or concentrated in groups located some distance from the central device?

    Looking forward to resolving these issues together!
    Once again I apologize for my late response.

    Best regards,
    Karl

    Best regards,
    Karl

  • Hi Karl

    Glad to read all is well.

    In the meantime I actually been working on a different project and just returned to this one again a few days ago Blush so its ok .. but anyway 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).

    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)

    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.

    Questions:

    1. 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. (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)
    2. 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 ?
    3. Also, if you think there is a better solution then the tree structure ?

    I was suggested to work with mesh but I don't need the units to talk to each other and I think there will be a lot of latency in a mesh .. maybe I am wrong.

     

    Anyway, One other issue I am thinking of is that I don't have an energy issue, all the units are constantly connected to a power supply, all units are moving in a range of 2 meter square. 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 ?

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

    (i have sdk 16.0, the field units are nrf52832 working with s132 NINA boards) 

    Best regards

    Ziv

Related