1 2 3 Previous Next 37 Replies Latest reply on Oct 16, 2017 6:01 AM by e.pratt_1639216

    Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next

    kumar.firmware_2653741

      Hi Team,
      I need your kind support on the following.
      I have configured my Cypress BLE module as observer.
      My module will listen to the broadcasters advertisements and send scan requests and receives scan response perfectly. All this is working properly.
      But the actual problem here is when I receive advertisement, I am trying to modify the device address i.e. scan Request, it is changing and reflecting for the next advertisement received, not immediately. Why is this happening? Is there a way to avoid to this? How this problem can be solved?
      when I receive an advertisement, I need to change scan request(device address) and broadcaster should receive this instantly and not for the next advertisement.
      Can you kindly provide your support for the same. Hope I am clear in my explanation.
      Thanks, Regards,

         

      Kumar

        • 1. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
          e.pratt_1639216

          Why do you expect/want it to change t he device address immediately? The scan requests might have already been sent out before you changed the address; The address/configuration settings generally can only be changed at the intervals when the BLE radio is not active, otherwise you would get corruption of radio packets being sent out while data configuration is being changed. I'm not sure you can change it "immediately", but you should be able to change it before sending out the next scan request. It might involve stopping scanning, changing the settings, then re-enabling the scanning in order for it to work.

             

          Is the issue how fast the device address is changing? Is it a problem with the device address not changing at all? 

          • 2. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
            kumar.firmware_2653741

            Hi Pratt,

               

            Thanks for your immediate response.

               

            My application is like that when I receive advertisement, I need to change scan request(device address) and send.

               

            As I told clearly, scan request is changing, but it is lagging one iteration. I receive ADV1 - I send SCAN REQ1

               

            I receive ADV2 - I send SCAN REQ2.

               

            But the receiver(device) of scan requests receive SCAN REQ1 for ADV2 and Scan REQ2 for ADV3.

               

            One iteration is lagging. 

               

            Basically, as soon as I receive ADV, in the application event handler, CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT, I change Scan Request, but the change reflects when the next ADV is received.

               

            So Basically I understand before, the event handler is rasied, radio alreadysent scan Request. Kindly confirm my understanding.

               

            Is there a way to solve this problem? Can you please confirm. Is there any work around for the same.

               

            Thanks,Regards.

            • 3. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
              e.pratt_1639216

              Hello Kumar,

                 

              Hmmmmm, it could be that you need to call cyble_processevents() to finish/fully update the scan request response, and it isn't being called in-time for the next advertisement.

                 

              If the BLE stack is processing the ADV2 already when you are trying to change the SCAN REQ2, then I wouldn't see a feasible way to change the scan request sent out.

                 

              If the advertisement hasn't be received by the hardware, then there should be a method/way to somehow change the scan request parameters before the next advertisement packet.

                 

              The event CYBLE_EVT_GAP_SCAN_REQ_RECVD might be helpful in determining if the software is handling your scan request parameter changes before you are getting the next advertisement packet. (Enabled by CyBle_SetAppEventMask())

                 

              (Sorry for not understanding what exactly you were asking in your original post :)

              • 4. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
                kumar.firmware_2653741

                Hi Pratt,

                 

                Thanks for your immediate response. Hope you are doing excellent. I was on forced emergency vacation for a month and back now.

                Unfortunately we could not conclude last time and come to a common agreement, can we do it now please.

                 

                Basically, as soon as I receive ADV, in the application event handler, CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT, I change Scan Request, but the change reflects when the next ADV is received.

                   

                So Basically I understand before, the event handler is rasied, radio already sent scan Request. Kindly confirm my understanding.

                   

                Is there a way to solve this problem? Can you please confirm. Is there any work around for the same.

                 

                Can you Kindly provide your support and close this with the common agreement.

                 

                Thanks,Regards

                Kumar.

                • 5. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
                  e.pratt_1639216

                  Hello Kumar,

                  Welcome back

                  There are several reasons that I can see for why it is behaving this way:

                  1. The hardware radio is already started/starting sending out the next scan request.

                  2. The cypress binary is written to check/change the scan request after it sends a scan request, and thus it will always lag by one iteration as you are seeing. (Would need cypress to confirm this)

                  3. Based on timing/other things the scan request data might not be getting updated/handled before the next advertisement comes through. (Cyble_Process_Events)

                   

                  If the cause is reason 1, there is no solution.

                  If the cause is reason 2, then Cypress would need to help you work through it.

                  If the cause is reason 3, then you would need to change the code you are running to try to speed up processing time. Basically, you would need to shorten the time from the GAPC_SCAN_PROGRESS_RESULT event finishing to the CyBle_Process_Events() finishing. Even then, you might not be able to make the code short enough to get it working.

                   

                  Ideally, you would have your application/code allow for a slight delay of the one or two advertisements before the scan request data changes. Otherwise, you will be constantly worrying about the timing getting slowed down or disrupted in some way causing a fatal program flow disruption. The simplest solution I would do is to program your code to allow a lag of one advertisement, as everything else is working

                   

                  Good Luck,

                  EPratt

                  • 6. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
                    kumar.firmware_2653741

                    Hi Pratt,

                    Thanks for your immediate response. Thanks for the explanation.As you concluded nothing can be done here, we need to accept it as Cypress BLE  System behavior and need to handle in application code.

                     

                    Another important question for you is, how and when there is a chance of BLE stack getting freezed or becoming unresponsive?

                     

                    When do you see BLE stack becoming unresponsive? what causes this behavior? Have you observed this any time in your testing. Rest of the system will be fine and running, only BLE stack becoming unresponsive? Kindly suggest.

                     

                    Thanks,Regards,

                    Kumar.

                    • 7. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
                      kumar.firmware_2653741

                      Hi Pratt,

                       

                      Can you kindly provide your thoughts/suggestions on the following before you go for weekend.

                       

                      Another important question for you is, how and when there is a chance of BLE stack getting freezed or becoming unresponsive?

                       

                      When do you see BLE stack becoming unresponsive? what causes this behavior? Have you observed this any time in your testing. Rest of the system will be fine and running, only BLE stack becoming unresponsive? Kindly suggest.

                       

                      Thanks,Regards,

                      Kumar.

                      • 8. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
                        e.pratt_1639216

                        Hello Kumar,

                         

                        Sorry I didn't see this before I headed out for the weekend

                        The BLE stack will become unresponsive or "freeze" when you call the API functions incorrectly. Afaik, it will not be locking up or causing issues if you are using the API functions in the correct order/sequence as defined by the documentation. I've seen it mess up when I was first playing with the APIs, but now that I understand more or less how it works, it hasn't given me issues.

                         

                        Epratt

                        • 9. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
                          kumar.firmware_2653741

                          Hi Pratt,

                           

                          Good Morning. Hope you had an excellent weekend. Thanks for your immediate response.

                           

                          I am running only observer code in my device, some times I see BLE stack freezes or becomes unresponsive. This happens some times after 4 to 5 days. This happens some times less than an hour also. Rest of the device works perfectly fine. Only BLE stack gets freezed. If I restart BLE stack, it works fine again.

                           

                          Lots of devices are sending Advertisements around my device, lots of interference, too many advertisements from too many devices will this be a problem? why BLE stack is getting freezed?

                           

                          If APIs are not called correctly, it should not work for 5 days properly right? and after restart of BLE stack it should not work properly right?

                           

                          What can go wrong here? Can you please help on this.

                           

                          Thanks ,Regards,

                          Kumar.

                          • 10. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
                            kumar.firmware_2653741

                            Hi Pratt,

                             

                            Can you kindly help me to get out of the above mentioned critical issue as soon as possible. It has become highly critical, because the nature of issue is random.

                             

                            Kindly provide support on the same.

                             

                            Thanks, Regards,

                            Kumar.

                            • 11. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
                              e.pratt_1639216

                              So, if I understand correctly: You are only running in observer mode, and you never call any other BLE APIs after starting the BLE stack?

                              Possibly, if you aren't calling the CyBle_ProcessEvents() quickly enough, the BLE stack could be running into a timeout issue with handling the incoming advertisements. Try to call the CyBle_ProcessEvents() at least once on each iteration through main?

                              If you are receiving alot of advertisements, then you will need to be handling all of the advertisements, but if you handle them quickly enough I wouldn't see it as an issue.

                              If your device is working for several days of getting dozens of advertisements per minute, then the software for calling the APIs and code would be less likely to be the source of the issues

                              On the other hand, something like the radio/chip overheating or running into a limit with the handling of the advertisements might be the cause.

                               

                              Things I would test/try: Call CyBle_ProcessEvents() after calling BLE APIs and during the main() loop to ensure the BLE events are handled quickly and frequently.

                              There could be issues with code that doesn't run often, or an issue that compounds and thus doesn't show up right away. But, that would involve looking through the application code: I would expect you don't want to post your code on the internet...

                               

                              If you are restarting the BLE stack to fix the issue, then the problem is most likely in one of two places: Cypress' BLE radio code, or your application code.

                              • 12. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
                                kumar.firmware_2653741

                                Hi Pratt,

                                Good Morning. Thanks for your immediate response.

                                I am afraid on resetting the BLE stack, when it is getting freezed, it is solving the issue. I am not resetting any other part of the code.

                                So issue cannot be in my application code.

                                I guess issue has to be in BLE radio code or  running into a limit with the handling of the advertisements? Is there any limit like that? I am receiving currently 10 to 15 advertisements every second. will this be a problem. If radio is overheating on restart how it will solve the problem.

                                I don't expect it as hardware issue, it should be software issue only.

                                My for loop just has this

                                for(;;)

                                    {

                                       CyBle_ProcessEvents();  

                                       // Check if time of packet received is greater than 60 seconds, reset BLE stack

                                    }

                                 

                                Also If a desired advertisement is received, I will change the device address in the event handler.

                                 

                                Can you elaborate on this? what is BLE stack running into a timeout issue? what is the minimum/maximum time out for BLE stack. I am calling CyBle_ProcessEvents();    on every iteration in main. SO here where is the chance of BLE stack getting freezed?  what are the conditions for it to get freezed if we know then we can easily understand what is the problem. Please elaborate on this.

                                 

                                if you aren't calling the CyBle_ProcessEvents() quickly enough, the BLE stack could be running into a timeout issue with handling the incoming advertisements. Try to call the CyBle_ProcessEvents() at least once on each iteration through main?

                                 

                                Please let me know how to solve this?

                                 

                                Thanks, Regards,

                                Kumar.

                                • 13. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
                                  e.pratt_1639216

                                  My for loop just has this

                                  for(;;)

                                      {

                                         CyBle_ProcessEvents(); 

                                         // Check if time of packet received is greater than 60 seconds, reset BLE stack

                                      }

                                  • Based on you saying this is what your code does, then you shouldn't be having issues with the CyBle_ProcessEvents() being handled quickly enough.
                                  • Like you said, resetting the BLE radio fixes your issue, so there must be something software (not hardware) related causing the problem.
                                  • 10-15 advertisements per second should be fine (that's about 200 ms to process each on average) I was thinking you would say a number like 500 or something
                                  1. Have you tried running the device with a debugger connected to see what the state/variables are set to when it "freezes"?
                                  2. If you can post your complete project, it would help for us to see the configuration settings, otherwise you could ask Cypress to look at the project themselves, and give you tips/pointers on your code.
                                  3. Have you tried running one of the example observer projects? If the example one works fine, then it will be a difference between your project and the example project
                                  4. Depending on what your code for the event handler for the BLE radio is doing, that could be a source of the issue?
                                  • 14. Re: Change in Scan Request(device address) done when advertisement is received is not reflected immediately, but reflected for next
                                    kumar.firmware_2653741

                                    Hi Pratt,

                                    1. Have you tried running the device with a debugger connected to see what the state/variables are set to when it "freezes"?

                                    what variables I can check. can you suggest please? I can only see the void ApplicationEventHandler(uint32 event, void *eventparam) event type I guess, any thing else apart from this?

                                     

                                    2.Please find the screen shot for the project settings attached. I don't think or observer code there are any big settings than this.

                                     

                                    3. I have not run example project yet. But nature if the issue is random and at times complex to reproduce, but the more number of advertisements targeted to the device ie @100milli seconds, chance of getting freeze is more.

                                     

                                    4.Depending on what your code for the event handler for the BLE radio is doing, that could be a source of the issue?

                                    can you elaborate on this? how it will effect feezing?

                                    under this CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT, I am calling RTC_GetUnixTime() to note time of received event and CyBle_SetDeviceAddress(data);

                                     

                                    5. is there a way to do reverse engineering why stack gets freezed, if you have access to BLE stack.

                                     

                                    Thanks,Regards,

                                    Kumar.Settings.png

                                    1 2 3 Previous Next