- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
CyBle_GattsWriteAttributeValue(&imuHandle,FALSE,&cyBle_connHandle,CYBLE_GATT_DB_PEER_INITIATED);
Thanks a lot for your help!!
Alejandro Villa
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
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;
CyBle_GattsWriteAttributeValue(&imuHandle,FALSE,&cyBle_connHandle,CYBLE_GATT_DB_PEER_INITIATED);
Regards,
- Madhu Sudhan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
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;
CyBle_GattsWriteAttributeValue(&imuHandle,FALSE,&cyBle_connHandle,CYBLE_GATT_DB_PEER_INITIATED);
Regards,
- Madhu Sudhan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Good morning, Madhu 😉
Can you edit your post and replace the " >>0xFF" with " & 0xFF"
The ">> 34" is a ">> 24"
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Thanks,
Rob Berry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hallo,
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"
Regards,
Dominik Führer