How do I register to receive a callback when a characteristic is read by the client?

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

cross mob
Anonymous
Not applicable

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?

1 Solution
VictorZ_46
Employee
Employee
5 comments on blog 25 sign-ins 250 likes received

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);

}

View solution in original post

4 Replies