4 Replies Latest reply on Sep 21, 2020 4:08 AM by GaneshD_41

    Can't read from BLE Device Android App

    user_3678521

      Hello,

      So I'm creating a BLE connection between my PSoC 6 BLE and a Android App, the connection is etablished and works. But I dont get the read value from the PSoC.

      If i use the app CySmart and read, it works perfectly.  So I think i might do somthing wrong in my app part.

       

      Here is the app: app Link

      PSoC project:  psoc Link

       

      Hope someone can help me

        • 1. Re: Can't read from BLE Device Android App
          DheerajK_81

          Please read the section Read BLE Attributes and Receive Gatt Notifications section of the Android BLE Documentation at this link: Bluetooth low energy overview  |  Android Developers

           

          This should help you understand the right way to implement the APIs. The application you are trying to implement looks similar to the Android Bluetooth LE Gatt Sample code that is readily available. You can make use of that directly.

           

          Go to File > New > Import Sample > Bluetooth LE Gatt.

           

          Regards,

          Dheeraj

          • 2. Re: Can't read from BLE Device Android App
            user_3678521

            So at the moment I read a single int from my PSoC 6 BLE device, and another letter 'M' converted to a integer and back to a 'M' on the app-side. The reason I only read a SIGNLE 'M' is because I don't know how to send a whole string like 'Mads Sander'. I think the issue I'm having is on the PSoC side where I don't know how to read a whole string.

             

            for(;;)

            {

                /* Place your application code here. https://www.youtube.com/watch?v=Aeip0hkc4YE*/

                cy_stc_ble_gatt_handle_value_pair_t serviceHandle;

                cy_stc_ble_gatt_value_t serviceData;

               

                //this is the variables I've declared earlier in the code

                //static uint8 data[1] = {0};

                //static char * ValStr;

               

                //here I just have a simple Integer which count up every sec

                serviceData.val = (uint8*)data;

                serviceData.len = 1;

               

                serviceHandle.attrHandle = CY_BLE_CUSTOM_SERVICE_DEVICE_OUTBOUND_CHAR_HANDLE;

                serviceHandle.value = serviceData;

               

                Cy_BLE_GATTS_WriteAttributeValueLocal(&serviceHandle); //sending the data to -> OUTBOUND

               

                //this part should probably not be in a for-loop, but for now it is.

                ValStr = "Mads Sander Hoegstrup"; //I want read whole string on my android APP

                serviceData.val = (uint8*) ValStr; //this only takes the 'M' and thats the only variable I can read from my APP not the rest of the string

                serviceData.len = 1; //Does not help to increase, if it's more than 1 I read 0 and not a letter

               

                serviceHandle.attrHandle = CY_BLE_CUSTOM_SERVICE_DEVICE_OUTBOUND_2_CHAR_HANDLE;

                serviceHandle.value = serviceData;

               

                Cy_BLE_GATTS_WriteAttributeValueLocal(&serviceHandle); //sending the data to -> OUTBOUND_2

               

                data[0]++;

                CyDelay(1000);

            }

             

            Here you can see that I revice the right values, a Integer and a String, but only the letter 'M' and not the string 'Mads Sander Hoegstrup'

            JhSDa.png

            Just ask if you want more information

            • 3. Re: Can't read from BLE Device Android App
              user_3678521

              Found out I was useing a uint8: length 1, and changed that to a utf8s: length 23. and now I recive a whole string, do you know how long the MAX of a utf8s string is?

              • 4. Re: Can't read from BLE Device Android App
                GaneshD_41

                Hi Mads,

                 

                The maximum length of the characteristic length you can set is 512.

                 

                But for maximum throughput, we recommend the following settings:

                 

                ATT MTU-498, GATT Char length -495, LL payload - 251

                 

                ATT MTU - 247, LL Payload-251bytes,  GATT Char length -244 bytes

                 

                Thanks

                Ganesh