7 Replies Latest reply on Mar 22, 2018 5:19 AM by smita.kotwal_3009571

    Android App disconnects from BLE

    smita.kotwal_3009571

      I am using CY8CKIT-042-BLE for android application development. My problem is the android app disconnects from BLE after 30 secs. I donot call BluetoothGatt.disconnect() anywhere in my code. I need to have a persistent connection throughout. Please help.@@@@@

        • 1. Re: Android App disconnects from BLE
          ionascu.marianemanuel_1654946

          Hello,

           

          I am not very sure what the problem may be but I can give you some hints from your description. I think the problem is on the PSoC firmware that you implemented. The 30 seconds is very likely to be a timeout cause by BLE connection from various reasons, the most common being: you try to write a characteristics, or a CCCD descriptor and the PSoC does not return a response. Again if you have some security enabled, such as a passkey, and you do not do the pairing properly this may result again in a timeout after 30s. Please be sure you treat the write events and pairing correctly on the PSoC firmware.

          • 2. Re: Android App disconnects from BLE
            smita.kotwal_3009571

            Thanks Marianemanuel, but I am not a firmware developer hence not aware about passkey. I write characteristics to firmware through Android App and also get the response. But when I try to write another characteristic to BLE I get "BLE DISCONNECTED EVENT: ERROR::0x13" and "idle state" error and disconnect happens automatically after around 30secs of pause.

            • 3. Re: Android App disconnects from BLE
              ionascu.marianemanuel_1654946

              Hello,

               

              The event received seems very likely caused by the fact that the firmware did not treat some events. More likely the write you intend to do is not treated in the firmware and it causes the disconnect due to timeout. Unfortunately, I cannot figure out other reason in this moment. Get in touch with the firmware developer and ask about that characteristic you want to write. Again, this forum covers in general PSoC firmware questions and without knowing exactly what is happening in the firmware I personally do not have any more info.

              Hope this helps.

              • 4. Re: Android App disconnects from BLE
                e.pratt_1639216

                If the device always disconnects instead of sending a second BLE response with the data for your read/write command, then it could be that the firmware handling the first read/write succeeds, but then crashes in code after handling it properly.

                If the device only crashes on certain characteristics for read/write, then those specific characteristics aren't handled properly.

                If the device only sometimes crashes on certain/random characteristics, then the firmware is mishandling an event, a timer, or some other (possibly unrelated) problem is occurring.

                Without seeing the firmware for the project, or having more information, it would be mostly guesswork to figure out what is wrong.

                • 5. Re: Android App disconnects from BLE
                  smita.kotwal_3009571

                  Thanks Pratt and Marinemanuel,

                  I get error code 0x13 which means User terminated connection according to BluetoothGatt specification. Is it possible that the app disconnects due to Android supervision timeout?

                  • 6. Re: Android App disconnects from BLE
                    e.pratt_1639216

                    See this related thread: Connection Terminated by Local Host (0x13) error - Bluetooth® low energy Forum - Bluetooth® low energy - TI E2E Communit…

                    If there is a timeout for the android side telling it to disconnect when a command/request to the remote device fails, then the remote device is not replying to the command/request and the android application is timing out due to the Android supervision timeout.

                    THUS, in order to truly fix the issue, you would need the engineer who wrote the firmware code on the PSoC 4 to add more code for handling the events that are failing to respond to the android app. Or, change the android app to not use the commands/requests that fail.

                    An easy way to test this theory is to start with no commands/requests from the GATT database on connection with the PSoC 4, and then slowly add the commands/requests that you want to use in your android application one by one until you run into the same 30s disconnect window. Then you will know which commands/requests are failing and causing the timeout disconnection.

                    • 7. Re: Android App disconnects from BLE
                      smita.kotwal_3009571

                      Thanks Pratt. I shall check this solution.