This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/CC2640R2F: blestack multirole example : continuously read advertising data of neighbours devices

Part Number: CC2640R2F
Other Parts Discussed in Thread: CC2640

Tool/software: Code Composer Studio

Hi everyone,

It is my first post here and I hope I didn't anything wrong.

I'm a beginner with the CC2640R2F hardware and software and I use the "multirole" example of "blestack" as a start point.

My goal is to read ALL the advertising frames sent by the devices around. I need to get all the advertising frames because latency is a critical point and I expect to not loose some with would increase latency.

I tried the solution below, which seems to work, but the latency is too long (sometime, half a second or more). As the advertising device send frames with an interval of 100ms, I would get the data on the CC2640 with 100ms latency maximum.

  • First, I start a scan by adding the line "mr_doScan(0);" just before the infinite loop of "static void multi_role_taskFxn(UArg a0, UArg a1)"
  • I read advertising data in "case GAP_DEVICE_INFO_EVENT:" of function "static void multi_role_processRoleEvent(gapMultiRoleEvent_t *pEvent)" : this code is executed each time a device is discovered
  • Then, when scan ends, "case GAP_DEVICE_DISCOVERY_EVENT:" of same function is executed and I  restart a scan thanks to "mr_doScan(0)"

Then I need to tweak the scan duration (#define DEFAULT_SCAN_DURATION) to a smaller value, such as 150-200 ms, to get a better latency. If the scan duration is too short (< 100 ms), latency starts to rise again, the minimum seems to be around 150 ms.

Is this the optimal way or can I do it differently ?

Thanks,

Damien

  • Hi,

    I forgot to say that this code makes the software crash after some time (a few tens of seconds, or a few minutes), even if I don't add anything in "case GAP_DEVICE_INFO_EVENT:" to read advertising data.

    So, to reproduce the bug, you just have to add 2 lines in a fresh "multirole" example:

    • "mr_doScan(0);" after "multi_role_init();"
    • "mr_doScan(0);" after "Display_print1(dispHandle, MR_ROW_STATUS1, 0, "Devices Found %d", scanRes);"

    If someone has an idea about what I'm doing wrong, it would help me a lot.

    Thank you,

    Damien

  • Part Number: CC2640R2F

    Tool/software: Code Composer Studio

    Dear all,

    I work on CC2640R2F with "simple_peripheral" example.

    I would know how to read advertising data sent by the other peripherals around.

    Thanks,

    Damien

  • simple_peripheral cannot scan advertising from other BLE device. You have to use simple_central or multi_role example which has BLE central capability to scan BLE advertising from other devices.

  • Hi Chen,

    Thank you for your fast answer.

    I used "multirole" example at the begging but I couldn't make it works. I asked the question in this thread, which didn't get any answer :

    If you could tell me how to do so in "multirole" it would be very helpful.

    Regards,

    Damien

  • Hi Damien!

    Processes such as advertising and scanning for advertisements are very probabilistic events. These processes can be affected by environmental factors and it is very difficult to ensure very consistent results. I believe the the latency you have achieved is very good and it may not be feasible to improve. If the advertisement window is changed, then the scanning window must also be changed. A good measure is to have a scanning window that is twice as long as your advertising window. That should make it unlikely for any information to be lost.

    I suggest looking over the SimpleLink Academy resource for this board. It contains very useful information and goes a bit more in-depth into how to alter the scanning and advertising window to achieve a certain result. Specifically, I suggest looking at the Scanning and Advertising lab.  Another resource that may be very helpful is the User's Guide for this device's SDK.

    Regards,

    Jan Iglesias

  • Hi Damien,

    Merging threads here, please do your best to limit one thread per topic that you wish to discuss. Creating multiple threads complicates our ability to support E2E effectively and leads to weaker support. 

    Did you read through the resource Jan provided you? Multi-role is the same as central just with the peripheral features as well, so the same concepts would apply. Were you able to do what you want with the Central Role?

  • Hi,

    Thank you for you answer. In fact, the Scanning and Advertising lab of  SimpleLink Academy answers my question.

    To read continuously advertising data sent by other devices, I did the following :

    • DEFAULT_MAX_SCAN_RES set to 0 to enable unlimited scan. Scan results are only available under GAP_DEVICE_INFO_EVENT
    • DEFAULT_SCAN_DURATION set to 0 to scan during an unlimited time
    • DEFAULT_DISCOVERY_ACTIVE_SCAN to FALSE because I want to Rx only.
    • Finally, ENABLE_UNLIMITED_SCAN_RES set to TRUE
    • And I just start once the scan at the beginning of the software.

    So I get in "case GAP_DEVICE_INFO_EVENT:" each time an advertising frame is received.

    Thank you a lot