Client writing Characteristic Values for custom service

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

cross mob
Anonymous
Not applicable

Greetings,

   

Is there a good example showing how a client application can locate a specific service running on a peripheral and write updated characteristic values?  Right now my program is sitting in the CYBLE_EVT_GATTC_DISCOVERY_COMPLETE event, but am unsure how to go about writing a new CYBLE_GATTS_WRITE_CMD_REQ_PARAM_T which the peripheral receives.

   

Thanks,

   

Eric

0 Likes
1 Solution
Anonymous
Not applicable

UPDATE:  I did finally get the Write function working based on the example shown in the 100 Days: UART_to_BLE example.

View solution in original post

0 Likes
4 Replies
Anonymous
Not applicable

Heh, I don't know what the GATTC_DISCOVERY_COMPLETE event is, but here's the general sequence I use:

   

CyBle_GattcDiscoverPrimaryServiceByUuid(cyBle_connHandle, ServiceUUID);

   

Handle the CYBLE_EVT_GATTC_FIND_BY_TYPE_VALUE_RSP event for each service that matches the UUID.

   

CyBle_GattcDiscoverAllCharacteristics(cyBle_connHandle, attrHandleRange);

   

Handle the CYBLE_EVT_GATTC_READ_BY_TYPE_RSP event for each characteristic.

   

//You now have the handles for the service you are looking for, and the characteristics within the service.

   

//Note: there will be an event to signal the completion of the discover commands I believe, but you can also end them early (before completion) with the command CyBle_GattcStopCmd();

   

Now, you merely call the function CyBle_GattcWriteCharacteristicValue(cyBle_connHandle, &CYBLE_GATTC_WRITE_REQ_T); replacing the WRITE_REQ_T with a structure containing the data and metadata for writing your data to the specified characteristic.

0 Likes
Anonymous
Not applicable

Thank you for your response, but I am still a little confused.  I'm not sure exactly what you mean when you say: "Handle the .. event for..."

   

Currently I am calling the GattcWriteCharacteristicValue() with the handle returned by the CYBLE_EVT_GATT_CONNECT_IND event.  Is this incorrect? 

0 Likes
Anonymous
Not applicable

UPDATE:  I did finally get the Write function working based on the example shown in the 100 Days: UART_to_BLE example.

0 Likes
Anonymous
Not applicable

Sorry, the wording was as little poor. The handles for the services/characteristics you are using perfectly. I was referring to having a case to grab the handle values for the service/characteristics when those events occurred (hence, handling a generation of the event, not the handle value :))

   

Glad to hear that you got it working 🙂

0 Likes