Sending data to a custom service characteristic

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I need to connect to a Peripheral from a Central, write a value to a custom service characteristic and disconnect. I looked into the Day 6 sample ( from 100 projects in 100 days) and it looks like it's close to what I need.but it uses the Alert service and CyBle_IascSetCharacteristicValue() API. In my case there is a custom service and a characteristic (4 bytes)

Questions

1. What API should be used to write a custom service characteristic  with known UUID of both?

2. The code in day 6 sample calls CyBle_GattcStartDiscovery. In my case, with  UUID of the service and characteristic known, is there a need for that?

Thank you

Andy

0 Likes
1 Solution
2 Replies
Anonymous
Not applicable

1. You will want to use the function CyBle_GattcWriteCharacteristicValue(cyBle_connHandle, ptrattrWriteStructure)

Where ptrattrWriteStructure is a pointer to a structure of type CYBLE_GATTC_WRITE_REQ_T

And the following 3 parts of the structure need to be written for it to work correctly:

    ptrattrWriteStructure.attrHandle = uint16 serviceHandle; (0-x where x is the first byte of the service that you are referring to. The length iirc)

    ptrattrWriteStructure.value.val = uint8 data[]; pointer to uint 8 array

    ptrattrWriteStructure.value.len = uint8 dataLength; single byte length of uint 8 pointer array

2. Cyble_GattcStartDiscovery() is only needed to determine the handle value of the service for use as the parameter above. If you have a constant profile/services for the GATTDB, then the handle will never change (It is compile-time-constant), and thus you can use a hardcoded handle value if you don't have need for changing the UUID or handle values of the device.

0 Likes