cancel
Showing results for 
Search instead for 
Did you mean: 

Correct procedure for reading BLE characteristic values.

MSuva.1
Associate III

I am currently trying to read the value from a characteristic after detecting that the user has written to it.

0693W00000Y8wKCQAZ.png 

I am calling aci_gatt_read_char_value() which is returning 0 (BLE success). From here I am expecting an event which triggers the aci_att_read_resp_event() function but I am not seeing that get called.

However, I am seeing that the Custom_STM_Event_Handler(void *Event) gets called directly after I call this function and the event code is:0693W00000Y8wLsQAJ.png 

I'm not sure what the issue here exactly. Should I be setting a flag and then calling the read function elsewhere? Or is there some other issue with my setup?

Thanks very much

Maks

1 ACCEPTED SOLUTION

Accepted Solutions
Remy ISSALYS
ST Employee

Hello,

Yes, with the modification you don't have to send the write response. So, when you received the write on server side the ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE event is generated and you can perform your action according to the write value received. You can look BLE_p2pServer example available in STM32CubeWB package, to see how manage the write (see PeerToPeer_Event_Handler function p2p_stm.c file).

Best Regards

View solution in original post

6 REPLIES 6
Remy ISSALYS
ST Employee

Hello,

When you received the ACI_GATT_ERROR_RESP_EVENT event, which error code do you have?

Best Regards

MSuva.1
Associate III

Hi Remy,

The ACI_GATT_ERROR_RESP_EVENT seems to have cleared up by itself. I'm not sure i'm going about this the write way at all. Is there a correct way to access the value that has just been written by the client?

0693W00000Y9aIjQAJ.png 

When the client writes to the variable the ACI_GATT_WRITE_PERMIT_REQ_VSEVT_CODE is triggered. Is it correct that I am calling the read function here? Or is there just some variable I can read to see what new value has been written to the characteristic?

Thanks very much,

Maks

Remy ISSALYS
ST Employee

Hello,

Before calling the read function, you should respond to the write permit request with the write response command. When ACI_GATT_WRITE_PERMIT_REQ_EVENT is received, the application has to check whether the value being requested for write can be allowed to be written and respond with the command ACI_GATT_WRITE_RESP. You can refer to STM32WB_BLE_Wireless_Interface.html documentation to have more detail about ACI_GATT_WRITE_PERMIT_REQ_EVENT and ACI_GATT_WRITE_RESP.

Best Regards

MSuva.1
Associate III

Hi,

I've removed these from the GATT attributes now:

0693W00000Y9i5qQAB.pngI want the client to write without me having to give any sort of response and I want to be able to read what they wrote immediately.

I've removed the "wait for response" GATT attributes.

0693W00000Y9iBbQAJ.pngI assume this removes the necessity for me to send any sort of "ACI_GATT_WRITE_RESP"?

What is the step after this to access the newly written value?

Thanks again

Remy ISSALYS
ST Employee

Hello,

Yes, with the modification you don't have to send the write response. So, when you received the write on server side the ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE event is generated and you can perform your action according to the write value received. You can look BLE_p2pServer example available in STM32CubeWB package, to see how manage the write (see PeerToPeer_Event_Handler function p2p_stm.c file).

Best Regards

MSuva.1
Associate III

This explanation and example have fixed my issue. Thanks very much Remy, much appreciated 🙂