- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SDK function legattdb_regWriteHandleCb() can be used to register to receive a callback when a characteristic is written to by the client.
Is there a similar function that can be called to register to receive a callback when a characteristic is read by the client?
If not, how can the application be made aware that a characteristic has been read by the client?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Unfortunately there is no read callback. but you can do it yourself. In the Create function register to process all GATT messages
lel2cap_regConnLessHandler(LEL2CAP_CID_LE_ATT, my_l2capHandler);
add a handler
void my_l2capHandler(LEL2CAP_HDR *l2capHdr)
{
LEATT_PDU_HDR *gattPtr = (LEATT_PDU_HDR*) (l2capHdr +1);
LEATT_PDU_READ_REQ_HDR *p_read_read = (LEATT_PDU_READ_REQ_HDR *)gattPtr;
int opcode = LEATT_OPCODE_MASK & gattPtr->attrCode ;
int handle = p_read_read->attrHandle;
ble_trace2("gatt handle:%04x opcode:%d", handle, opcode);
if ((opcode == LEATT_OPCODE_READ_REQ) && (handle == "handle of your attribute"))
{
// do whatever you need
}
// call the standard handler where peer will grab value of the attribute from the GATT DB
leatt_l2capHandler(l2capHdr);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Unfortunately there is no read callback. but you can do it yourself. In the Create function register to process all GATT messages
lel2cap_regConnLessHandler(LEL2CAP_CID_LE_ATT, my_l2capHandler);
add a handler
void my_l2capHandler(LEL2CAP_HDR *l2capHdr)
{
LEATT_PDU_HDR *gattPtr = (LEATT_PDU_HDR*) (l2capHdr +1);
LEATT_PDU_READ_REQ_HDR *p_read_read = (LEATT_PDU_READ_REQ_HDR *)gattPtr;
int opcode = LEATT_OPCODE_MASK & gattPtr->attrCode ;
int handle = p_read_read->attrHandle;
ble_trace2("gatt handle:%04x opcode:%d", handle, opcode);
if ((opcode == LEATT_OPCODE_READ_REQ) && (handle == "handle of your attribute"))
{
// do whatever you need
}
// call the standard handler where peer will grab value of the attribute from the GATT DB
leatt_l2capHandler(l2capHdr);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, this solution appears to be working well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is this still true after all these years? No simple registration to get a callback when a client reads a characteristic? That is pretty important for supporting basic services like the Current Time Service and plenty of others that are now appearing in BT-SIG service/profile development. Reading the current time isn't the only dynamic feature a client may need to read!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @BrRe_4481111 ,
This post is several years old. Our development SDK has grown since then. Please check the latest examples of the device of your interest. We have callback events to indicate when the peripheral receives a read request from the peer device. Please start a new discussion if you have further questions for better reach.
Bragadeesh