9 Replies Latest reply on Oct 16, 2015 7:52 AM by userc_15614 Branched from an earlier discussion.

    Connection down cause (con't)

      Hey userc_19497 i have the same issue of connection down as here: Re: Connection down cause

       

      As such, I tried a proper pairing but it take so much time to pair; the phone take so much time to discover services and the wiced sense can't evaluate the connection down event: after disconnection caused by the phone the device can't make advertissement again.

       

      I put the conidle_timer=0 and i have added this two lines in connection_up for pairing:

      lesmp_pinfo->pairingParam.AuthReq  |= LESMP_AUTH_FLAG_BONDING;

      lesmp_sendSecurityRequest();

        • 1. Re: Connection down cause (con't)

          Hello.

          To reiterate your problem:

          is there something that is causing disconnection and are you trying to figure out the cause of that disconnection?

          or are you wondering why the device won't advertise as you've expected (because you start advertising again in connection_down function) after the first proper pairing followed by the disconnect request sent by the phone?

           

          The former would require more debugging.

          The latter seems to be Android related problem.

           

          I'm not sure if this is true for all Android devices or if this is different for newer OS versions, but I've gotten the same results using Nexus 7 and 9 both with Android 5.1.1. After the first pairing is done (meaning before: BLE device doesn't show in the paired devices list in the Bluetooth Setting; after: BLE device shows up in the paired device list), the BLE device does not disconnect from the Android device even when close()/disconnect() method is called. Even after the Android app closes, the BLE device will stay connected to the Android device. In order to disconnect, you have to get out of range, disable Bluetooth in Android, or reset the BLE device.

           

          Try viewing traces from your device and see if it actually goes through connection down when the phone sends disconnect request after having paired with the device.

           

          As for taking so much time while pairing and discovering services, I don't know why. Try disabling the wifi on your phone and moving both devices closer. Perhaps it's because of the signal strength. (I am highly just speculating.)

           

          Can you let me know which one is your problem? And which phone are you using( iOS vs Android)? Thanks.

           

          James

          • 2. Re: Connection down cause (con't)

            userc_19497

            Well, i'am trying to understand the disconnection cause, i'am testing with two android devices (xperia Z and Xperia z2) and both of them use lollipop android version but they act differently with the same application. The xperia z2 rebound every connection try, unlike the xperia z that i have to delete the device from the phone to rebond in the next connection procedure. Yes i confirm that after bonding the device will not disconnect.

             

            But is it supposed that the user delete the bond device from the phone manually every connection to succed his connection ?? i don't see the utility of the BLE here.

            • 3. Re: Connection down cause (con't)

              So you are trying to understand the disconnection cause?

              Does that mean you get disconnected from your wiced sense and you don't know why?

              I'm a little bit confused because you previously wrote:

               

              the wiced sense can't evaluate the connection down event:

              "after disconnection caused by the phone the device can't make advertisement again.

              From this I thought you were asking to see why the wiced sense doesn't go through the connection_down callback function which means it doesn't properly disconnect from the phone when a disconnect request was sent by the phone.

               

               

              The xperia z2 rebound every connection try, unlike the xperia z that i have to delete the device from the phone to rebond in the next connection procedure.

              Can you tell me what you mean by rebound?



              But is it supposed that the user delete the bond device from the phone manually every connection to succed his connection ?? i don't see the utility of the BLE here.

              I think you are right about this. At least from my experience of using Android and BLE devices, it seems that after the initial pairing, the devices will stay connected unless disconnected by one of the following reasons: getting out of range, turning Bluetooth off on Android, forgetting the paired device in the Bluetooth Setting on Android, or resetting the BLE device.


              Thanks.


              James

              • 4. Re: Connection down cause (con't)

                userc_19497

                i'am asking for the two issues:

                • disconnection cause if the two devices don't bond
                • callback uncalled quickly; the wiced sense waise too much time to know about the disconnection
                • 5. Re: Connection down cause (con't)

                  re bond = bond again

                  • 6. Re: Connection down cause (con't)

                    Hello.

                     

                    ahmedhrabi wrote:

                    • disconnection cause if the two devices don't bond

                    This happens when you are calling lesmp_sendSecurityRequest(); and no pairing gets done. In order to stay connected, you need to make a proper pairing.

                     

                    ahmedhrabi wrote:

                    • callback uncalled quickly; the wiced sense waise too much time to know about the disconnection

                    I don't really know why this happens. My only guess is that it was not properly disconnected. i.e. wiced sense did not get any disconnect request from the connected device, but they were disconnected for some reason and I think after few unsuccessful connection tries, wiced sense calls the conndown callback. I think that's why it's taking so long for wiced sense to respond to disconnection. But I can't be certain for sure.

                     

                    Does this help?

                    Thanks.

                     

                    James

                    • 7. Re: Connection down cause (con't)

                      Hi, well i wil try to make a proper pairing (if you have ansample code of pairing can you write it) Thanks James.

                      • 8. Re: Connection down cause (con't)

                        I've attached a file that has example of functions that you need in order to get pairing.

                         

                        The big picture is:

                        1. Define callbacks

                        2. Register callbacks in the app_create function

                        3. Perhaps call lesmp_sendSecurityRequest function in connection_up callback (optional)

                         

                        Essentially, there are two callback functions that you need to define:

                        1. smp_bond_result

                        2. encryption_changed

                         

                        There is a comment in the file that talks about the difference of the two callbacks.

                         

                        Hope this helps.

                        Let me know if you need anything else. Thanks.

                        James

                        • 9. Re: Connection down cause (con't)

                          Thanks James for your support, but i have already used this two callbacks and the pairing process worked sometimes and other times don't.

                          This is the project if you want to take a look.

                          Best regards.