5 Replies Latest reply on Mar 23, 2017 7:33 AM by f.dominik0104_2223251

    Send Float


      Hi I'm trying to send a float number  I'm working with the Cypress BLE CY8C4248LQI-BL583, now im sending all the data in uint8_array but i have an array with length 90 so this decrease a lot the transfer speed, now I want to send all the data in float numbers but I don't know which function I need to use and how, because right now I'm using this one


        dataHandle.attrHandle = attrHandle;
        dataHandle.value.val = data;
        dataHandle.value.len = len;






      Thanks a lot for your help!!




      Alejandro Villa

        • 1. Re: Send Float
          Madhu Lakshmipathy



          The CyBle_GattsWriteAttributeValue can accept only arrays of uint8 type. A float value may be represented in 4 bytes and the Float value may be sent as an uint8 array with 4 elements.


          For example:


          float n;


          uint8 temp[4];


          temp[0] = n & 0xFF:


          temp[1] = (n>>8)>> 0xFF;


          temp[2] = (n>>16)>> 0xFF;


          temp[3] = (n>>34)>> 0xFF;


          dataHandle.attrHandle = attrHandle;
            dataHandle.value.val = temp;
            dataHandle.value.len = 4;






          - Madhu Sudhan

          • 2. Re: Send Float

            Good morning, Madhu ;-)


            Can you edit your post and replace the " >>0xFF" with " & 0xFF"


            The ">> 34" is a  ">> 24"





            1 of 1 people found this helpful
            • 3. Re: Send Float

              Thanks a lot Madhu and Bob,


              So there are not a function to send float, I need to separate my float numbers to send it through the BLE, so I don't understand why in the settings of the BLE it let me change the Type of the field that I want to send, because I always need to change the type into an array.


              I have another question, if I want to send more than 3 fields in each characteristics how do I send that, like the picture.




              Thanks again for your help 





              Alejandro Villa




              • 4. Re: Send Float

                The code above doesn't work. give an invalid operand to binary expressions (float and int) for the & 


                and the same error but (float to float ) with the >>


                How do i resolve this. I really want to send floats via BLE.




                Rob Berry

                • 5. Re: Send Float



                  I had the same issues and solved the problem with using an "union":


                  union {


                  float flData;


                  uint8 charData[4];


                   } data;




                  Now you can send the data as an uint8 array: "(uint8 *)&data.charData"






                  Dominik Führer