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.

CC2652R7: Enabling Periodic Advertisements in simple central

Part Number: CC2652R7
Other Parts Discussed in Thread: SYSCONFIG,

I am working on enabling reception of periodic advertisements in simple central code by creating a list of periodic advertisers as mentioned in GAP Scanner . I have added the policy 2 code in SimpleCentral_processAppMsg() function and have added other modifications as mentioned on the link.

 

After pressing discover devices on the terminal, the central device discovers devices for few seconds and comes back to same screen.

I was expecting the device to keep on listening to the periodic advertisements coming from the 3 peripheral configured in periodic advertisement mode. How do I enable the device to keep on listening to the periodic advertisements instead of coming back to discovering mode.

Values I have kept for few other parameters - 

Scan Interval, window = 150 msec

scan duration = 600000 msec

 pSyncParams.syncTimeout = 1000; 

  • Hi Garvit,

    Thank you for reaching out.

    • Can you confirm you have followed the steps "Enable the reception of the periodic advertisements" and "Handle the periodic advertisements reports"?
    • Can you specify how you handle the reports (please share your code snippet)?
    • Can you specify whether some GAP_SCAN_PERIODIC_ADV_REPORT_EVENT are received by the application?

    Best regards,

  • Hi Clement,

    1) I have Enabled the reception as mentioned in GapScan_enable API documentations 

    But I have not added GapScan_disable function as of now in code.

    2) I have added just a logging function to see whether the code is entering the GAP_SCAN_PERIODIC_ADV_REPORT_EVENT case and it is not entering in this case as of now.

    These are the changes I have made in SimpleCentral_processGapMsg function as of now.

    Thanks

    Garvit

  • Hi Garvit,

    Can you please ensure scan is disabled after the call to GapScan_PeriodicAdvCreateSync()? Then, as already done, ensure scan is re-enabled after receiving the GAP_SCAN_CREATE_SYNC_EVENT.

    Best regards,

  • Hi Clement, 

    I made the required changes but still doesn't work as expected.

    I have attached the project for you take a look at - 

     1832.simple_central_LP_CC2652R7_tirtos7_ticlang.zip

    Is it possible that the issue maybe arising out of peripheral side? The log functions added in the CASE SC_EVT_ADV_Report: of simplecentral_processAppMsg function does discover the peripherals once and because of that I am suspecting the issue is due to central side code

    Thanks,

    Garvit

  • Hi Garvit,

    I am afraid I need more information from your side to have a chance to help you.

    Taking back from the beginning

    - Can you please check you are getting some report for the periodic advertisers you want under the SC_EVT_ADV_REPORT event? If yes, are you finding the three addresses you are looking for?
    ==> If not, then we have to fix this first
    ==> If yes you can continue

    - Use a Bluetooth sniffer to verify whether the advertisers behave as you expect
    ==> Please provide the sniffer log if you are not sure

    - Instrument the central's code to add markers (i.e. UART print, local counters or others) under GAP_SCAN_CREATE_SYNC_EVENT, GAP_SCAN_PERIODIC_ADV_SYNC_EST_EVENT, GAP_SCAN_PERIODIC_ADV_REPORT_EVENT, GAP_SCAN_PERIODIC_ADV_SYNC_LOST_EVENT 
    ==> What are the events hit/not hit?

    - Under, SC_EVT_ADV_REPORT, can you please try to change the value of pSyncParams.options as following

               pSyncParams.options = SCAN_PERIODIC_USE_PERIODIC_ADV_LIST |
                                     SCAN_PERIODIC_REPORTING_INITIALLY_ENABLED;

    ==> Does it allow you to get some GAP_SCAN_PERIODIC_ADV_REPORT_EVENT?

    Regards,

  • Hi Clement,

    1) I have setup a breakpoint inside the if loop for checking if the advertisement are periodic advertisement and that breakpoint is hit before the device stops discovering as shown in the image below 

    2) Similarly I have setup breakpoints inside  GAP_SCAN_CREATE_SYNC_EVENT, GAP_SCAN_PERIODIC_ADV_SYNC_EST_EVENT, GAP_SCAN_PERIODIC_ADV_REPORT_EVENT but the first breakpoint inside GAP_SCAN_CREATE_SYNC_EVENT hits after central device has already stopped discovering as shown in image below

    So I am not receiving any reports and I have made modifications as you suggested in pSyncParams.options.

    Thanks

  • Hi,

    Great, thank you for sharing these elements.

    So I understand GAP_SCAN_CREATE_SYNC_EVENT is hit. Do you see the scan operation being re-enabled after entering GAP_SCAN_CREATE_SYNC_EVENT?

    If you remove the breakpoints on SC_EVT_ADV_REPORT and GAP_SCAN_CREATE_SYNC_EVENT, do you hit the breakpoint on GAP_SCAN_PERIODIC_ADV_SYNC_EST_EVENT?

    Best regards,

  • 1) Yes Clement, the scan operation is re-enabled only once in every trial I have done so far after hitting the breakpoint in GAP_SCAN_CREATE_SYNC_EVENT.

    2) No, the breakpoints are never hit for both the case GAP_SCAN_PERIODIC_ADV_SYNC_EST_EVENT and GAP_SCAN_PERIODIC_ADV_REPORT_EVENT.

  • Hi Garvit,

    May I kindly ask you to confirm you have enabled Periodic Advertising Sync within SysConfig for your project?

    Best regards,

  • Hi Clement,

    I have enabled this option on both peripheral and central side as well as added "USE_PERIODIC_SCAN" in predefined symbol as mentioned in the documentation of GAP scanner.

    I don't have a sniffer hardware with me, Is their is an alternate way to get that information ? 

    Thanks,

  • Hi Garvit,

    Can you also confirm you have enabled "Periodic Advertising" on the peripheral's side?

    In parallel, I am preparing and testing for you a periodic advertiser image to run on a CC2652R7 device.

    Regards,

  • Hi Clement,

    Yes, I enabled it on peripheral side as well.

    Really I can't thank you and TI enough for being so patient and helpful. Thanks a lot for your time and efforts in resolving this issue.

    Regards,

    Garvit

  • Hi Garvit,

    Here are some guidance (and hexfile) to enable periodic advertising: https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1294888/faq-cc2642r-periodic-advertising-with-cc2642r-cc2652r7

    Can you give a try to see if it helps?

    Best regards,

  • Hi Clement,

    The observation on central side is still same for me after doing the modifications as mentioned in above link.

    I will retry once again by starting with new simple peripheral code again and let you know if it starts to work properly.

    Thanks 

  • Hi Garvit,

    I have tested one more time and all seems to work on my side.

    Please reference this new thread for guidance on enabling synchronization with a periodic advertising train: https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1295835/faq-cc2642r-synchronizing-with-a-periodic-advertising-train-cc2642r-cc2652r7

    Best regards,

  • Hi Clement,

    I am still having same issue where the central device again and again returns to discovering mode. I don't understand how this can be termed as normal behavior if the central doesn't keep on listening to the periodic advertiser once it discovers it and synchronize with it. If I am synchronizing the central device to a periodic train I am expecting it to stay synchronized and keep on listening to the advertiser continuously. 

    I have set the scan duration as 600000 msec in sysconfg of central device but the device returns to discovering mode in few seconds. Shouldn't it keep on listening for 600000 msec?

    I have already added -
    GapScan_enable(0, 0, 0);

    as mentioned in FAQ to scan automatically but still it is coming back to discovering mode in few seconds.

    Attaching both central and peripheral code if you would like to take a look at them - 

    8345.simple_central_LP_CC2652R7_tirtos7_ticlang.zip

    simple_peripheral_LP_CC2652R7_tirtos7.zip

    Thanks,

  • Hi Garvit,

    It would be interesting for you to implement at first the exact same code as the one I have shared.
    I have noticed a few elements in your code that are incorrect:

    - On the scanner side, the call to GapScan_PeriodicAdvCreateSync() is incorrect as the advSID parameter is set to 0 while the advertisers are using "1" as advSID. Please fix this in simple_central.c.

    //uint8_t status = GapScan_PeriodicAdvCreateSync(0, &pSyncParams);
    uint8_t status = GapScan_PeriodicAdvCreateSync(pAdvRpt->advSid, &pSyncParams);

    - On the scanner side, the sync timeout is 10 seconds, while the advertising interval set on the advertiser side is 10 seconds too. This cannot work. Please run your initial tests using shorter advertising intervals (I recommend to use the same as me) so we can avoid running in timeout issues.
    Please modify the advertising intervals on the advertiser side (both through SysConfig and within the structure GAPADV_PARAMS_AE_NC_NS in simple_peripheral.c. 

    A few other elements may have an impact and should be considered in case the issue is not fixed

    - On the scanner side, please try NOT using the Periodic Advertiser List. This way we can compare our results.

    - On the advertiser side, you have changed the address mode. This may have an impact, so please consider reverting to public address mode in case the two previous elements

    I hope this will help,

    Regards,

  • Hello Clement,

    Apologies for late response, I was on leave for past couple of days. 

    I have modified the code as you suggested and currently I am making a network of 1 peripheral and 1 central working in periodic advertisement mode.

    I can see the numberOfPacket variable getting update in expression window - 

    I have enabled logging as well on the variable to see the timestamps and I have noticed some unusual behavior in timestamps. I tried changing the advertising interval of peripheral to multiple different values but the variable is getting updated at a time gap of every .3 sec in all the cases. I have attached the .json output from ROV, from serial 2 you can see variable getting updated at gap of .3 sec

    ti.loggers.utils.LogSinkBuf.Records.rod.zip

    Logging code is added in following way on central side -

    On peripheral side I have changed the advertising interval parameter in both sysconfig and global variable -

    Additionally, I have disabled all the GapAdv_enable commands associated with advertising set 1, 2. 

    Thanks,

    Garvit

  • Hi Garvit,

    Great to see so much progress!

    The interval of the periodic advertisements is set by the function GapAdv_SetPeriodicAdvParams.

    In the code I have provided to you, I set the periodic advertising interval to 300 ms (240*1.25). PLease consider this value so you can obtain the periodic advertising you want.

    Below snippet should get you 1 second interval:

            // Set Periodic Advertising parameters
            //GapAdv_periodicAdvParams_t perParams = {240, 240, 0x40};
            GapAdv_periodicAdvParams_t perParams = {800, 800, 0x40};
            status = GapAdv_SetPeriodicAdvParams(advHandleNCNS, &perParams);

    I hope this will help,

    Best regards,

  • Hi Clement,

    Apologies for the oversight, Now the timestamps are matching the expected values.

    I am working on creating a list of periodic advertisers now. The code modifications are based on - 

    1) GAP Documentation - policy 2 under Synchronize with a periodic advertising train section in GAP scanner documentation. 

    I have made changes in the code lines highlighted in yellow when compared to the one mentioned in documentation -

    a)  pSyncParams.options = SCAN_PERIODIC_USE_PERIODIC_ADV_LIST |
    SCAN_PERIODIC_REPORTING_INITIALLY_ENABLED;

    b)  pSyncParams.advAddrType = (uint8)pAdvRpt->addrType; // only ADDRTYPE_PUBLIC and ADDRTYPE_RANDOM are allowed
    osal_memcpy(pSyncParams.advAddress, pAdvRpt->addr, B_ADDR_LEN);

    c)  uint8_t status = GapScan_PeriodicAdvCreateSync(pAdvRpt->advSid, &pSyncParams);

    2) Synchronizing with periodic train , The FAQ you provided in previous answers.

    While debugging, I have set breakpoints on line 878 and 885 as shown in image below and both the breakpoints are getting hit - 

    But the expressions variable is not getting incremented now and neither it is getting logged in ROV. Are there any other steps I need to follow for enabling this?

    Expected outcome - If I set a periodic advertising interval for all the devices as 5 sec and have 3 peripheral devices than there will be 3 increments in numberOfPackets variable at an "x" timestamp followed by 3 increments at "x+5" timestamp. 

    Is this expected outcome correct or will there be only 1 increment per event ?

    Thanks,

    Garvit

  • Hi Garvit,

    Can you please verify the value returned by the GapScan_AddDeviceToPeriodicAdvList function?

    Also, you should ensure all the devices you want to synchronize with are added to the Periodic Adv List before calling GapScan_PeriodicAdvCreateSync. Here, as you only add one device to the list, there is no point in using the Periodic Adv List - i.e. you aren't saving any energy as you still form the sync one by one.

    Expected outcome - If I set a periodic advertising interval for all the devices as 5 sec and have 3 peripheral devices than there will be 3 increments in numberOfPackets variable at an "x" timestamp followed by 3 increments at "x+5" timestamp. 

    Is this expected outcome correct or will there be only 1 increment per event ?

    The expected outcome is correct.

    Regards,

  • Hi Clement,

    I am able to see return value as success for  GapScan_AddDeviceToPeriodicAdvList function.

    Regarding, ensuring  the devices are added to the Periodic Adv List before calling GapScan_PeriodicAdvCreateSync, I was under the impression that BLE stack will take care of that. Can you elaborate a bit on how can I ensure this without knowing the addresses of all the peripheral in advance?

    Also, I have 3 peripherals working in periodic advertisement mode instead of 1 when I am trying to create a periodic adv list at central.

    Thanks,

    Garvit

  • Hi Garvit,

    My point was you should call 3 times GapScan_AddDeviceToPeriodicAdvList to add all the advertisers to the list, and then eventually call GapScan_PeriodicAdvCreateSync. If you call GapScan_AddDeviceToPeriodicAdvList  and GapScan_PeriodicAdvCreateSync at the same time, then you have only one device in the list (so the list does not help you much).

    Regards,

  • Hello Clement,

    I have add 3 instances of GapScan_AddDeviceToPeriodicAdvList and all 3 are returning success status and are getting called twice as you can see in the ROV output but the numberOfReports variable isn't getting incremented. 

    I also tried keeping only 1 periodic advertiser and 1 instance of GapScan_AddDeviceToPeriodicAdvList but still the numberOfReports variable isn't getting incremented

    Regards,

  • Hi,

    It looks like you call three times the GapScan_AddDeviceToPeriodicAdvList  function with the same parameters. May I kindly ask you to explain your approach here?

    Best regards,

  • Apologies if I am missing something basic here.

    The way I understood this function is I have to pass 3 inputs to it which are available in "pAdvRpt".

    With the help of if Statement - "  if(0 != pAdvRpt->periodicAdvInt) "  - We have ensured only periodic advertiser are included in the list.

    When you asked me to " call 3 times GapScan_AddDeviceToPeriodicAdvList "  - one way for me is to call the function using loop or simply add 3 instances of same function which I have done in the code shared in previous reply.

    In the input variables to this function, the first 2 variables are unknown for me so I cannot specify them in advance and I have to rely on the values coming to the pAdvRpt variable hence same input parameters given in all 3 instances.

    Hope I was able to clarify the logic a bit.

    Regards,

  • Hi,

    Thank you for telling me.

    Calling the GapScan_AddDeviceToPeriodicAdvList() function three times with the same parameters means you are asking the stack to synchronize three times with the same advertiser. This cannot lead to the behavior you want (i.e. to synchronize with three different advertisers) .

    Regards,

  • Hi Clement,

    Is there any other resource you can share for getting this functionality? I am not sure about how to change the input parameters when I don't have any other variable to work with, which is holding the address of detected device.

    Is this more aligned with right way to approach this? - I have added an if condition on number of advertisers detected before GapScan_PeriodicAdvCreateSync function is called. But again I don't think this code will detect 3 periodic advertisers first.

    Thanks,

    Garvit

  • Hi Garvit,

    I see two options:

    - Option 1: You keep NOT using the advertising list (which is working for you). In order to form all the synchronizations, you repeat the same process several times.

    - Option 2: You use the advertising list feature. At each advertisement received, you add it to the advertising list. Once you have all the advertisers you want in the list, you trigger the synchronization.

    I hope this will help,

    Best regards,

  • Hi Clement,

    For option 2 - 

      #define ADVERTISER_LIST_SIZE 3
    int advertiserListCount = 0;
    GapScan_Evt_AdvRpt_t advertiserList[ADVERTISER_LIST_SIZE];
    
    case SC_EVT_ADV_REPORT:
        {
            GapScan_Evt_AdvRpt_t advertiserList[ADVERTISER_LIST_SIZE];
            GapScan_Evt_AdvRpt_t* pAdvRpt = (GapScan_Evt_AdvRpt_t*) (pMsg->pData);
    
            if(0 != pAdvRpt->periodicAdvInt)
            {
                // this is a periodic advertisement
    
                // add the advertiser's data to the advertising list
                advertiserList[advertiserListCount++] = *pAdvRpt;
    
                // check if we have all the desired advertisers
                if (advertiserListCount >= ADVERTISER_LIST_SIZE) {
                    // add the device to the Periodic Advertiser List
                    for (int i = 0; i < ADVERTISER_LIST_SIZE; i++) {
                        GapScan_AddDeviceToPeriodicAdvList((uint8)advertiserList[i].addrType,
                                                           advertiserList[i].addr,
                                                           advertiserList[i].advSid);
                    }
    
                    Log_printf(LogModule_App1, Log_INFO, "ReturnValue1 = %d ", returnValue1);
    
    
                // connect the devices on the Periodic Advertiser List.
                GapScan_PeriodicAdvCreateSyncParams_t pSyncParams;
    
                pSyncParams.options = SCAN_PERIODIC_USE_PERIODIC_ADV_LIST |
                        SCAN_PERIODIC_REPORTING_INITIALLY_ENABLED;
                //            pSyncParams.advAddrType = (uint8)pAdvRpt->addrType; // only ADDRTYPE_PUBLIC and ADDRTYPE_RANDOM are allowed
                //            osal_memcpy(pSyncParams.advAddress, pAdvRpt->addr, B_ADDR_LEN);
    
                pSyncParams.skip = 0; // should be between 0 and SCAN_PERIODIC_SKIP_MAX
                pSyncParams.syncTimeout = 1000; // synchronization timeout for the periodic advertising train is 1000*10ms = 10s
                // should be between SCAN_PERIODIC_TIMEOUT_MIN and SCAN_PERIODIC_TIMEOUT_MAX
                pSyncParams.syncCteType = SCAN_PERIODIC_CTE_TYPE_ALL;
                advertiserNumber++;
    
                uint8_t status = GapScan_PeriodicAdvCreateSync(1, &pSyncParams);
    
    
                if(SUCCESS != status){
                    // handle error
                }
    
                GapScan_disable("");
    
                break;
                }
            }

    Is this the right implementation for list creation and than triggering the synchronization?  - numberOfReports variable is still not getting incremented.

  • Hi,

    I don't think you need to consume some memory with the "advertiserList" table. You can directly call GapScan_AddDeviceToPeriodicAdvList() with the advertisement set identified.
    The rest looks ok.

    I would recommend to verify the advertisement interval used by the advertisers is small enough compared to the timeout set. In addition, try to run the debug as we did together earlier (i.e. setting various breakpoints in several places).

    Best regards,

  • Hi Jan,

    7801.simple_central_LP_CC2652R7_tirtos7_ticlang.zip

    2133.simple_peripheral_LP_CC2652R7_tirtos7.zip

    I am working on CC2652R7 Boards, setup of 3 peripherals and 1 central.

    Thanks,

    Garvit

  • Hi Garvit,

    Thank you for the archives. I am able to build these projects locally and have sourced the correct boards. I will follow up via email and will close this thread for now. Slight smile

    Best Regards,

    Jan