cancel
Showing results for 
Search instead for 
Did you mean: 

Basic ble reading for STM32WB

Taxara
Associate III

Hi Guys,

I have problems reading. I have followed the STM32WB Workshop on stm32wb (using mx version 5.4.0). Now i'm trying to read but all examples seem to only use notifying and writing.

I have the following char created and added some default value.

aci_gatt_add_char(SvcHandle,
          UUID_TYPE_128, &uuid16,
          1,
          CHAR_PROP_READ | CHAR_PROP_WRITE_WITHOUT_RESP,
          ATTR_PERMISSION_NONE,
          GATT_NOTIFY_ATTRIBUTE_WRITE | GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP,
          10,
          0,
          &(AlarmThresholdHandle));
 
 
 uint8_t pData[1] = {59};
 aci_gatt_update_char_value(SvcHandle,
                AlarmThresholdHandle + 1,
                0, /* charValOffset */
                1, /* charValueLen */
                pData);

    

Within server app handler it enters this case when im reading, and found the right handler. This is the part where i get lost, what to do next? I implemented the following but that does not work.

case EVT_BLUE_GATT_READ_PERMIT_REQ:
 {
     aci_gatt_read_permit_req_event_rp0* attributeToRead;
     attributeToRead = (aci_gatt_read_permit_req_event_rp0*)blue_evt->data;
 
     if(attributeToRead->Attribute_Handle == AlarmThresholdHandle + 1)
     {
 
      uint8_t pData[1] = {5};
 
      retval = aci_gatt_update_char_value(SvcHandle,
                     AlarmThresholdHandle + 1,
                     0, /* charValOffset */
                     1, /* charValueLen */
                     pData);
 
     }
     returnValue = SVCCTL_EvtAckFlowEnable;
}

Once i passed here i cant trigger any new events anymore.

I would like to see some examples of reading or get some feedback on which steps to preform to read successfully.

Thanks in advance,

1 ACCEPTED SOLUTION

Accepted Solutions
JSHAR.1890
Associate II

Read request must always be completed with

(void)aci_gatt_allow_read(read_permit_req->Connection_Handle);

 switch(event_pckt->evt)
  {
    case EVT_VENDOR:
    {
      blue_evt = (evt_blue_aci*)event_pckt->data;
     
      switch(blue_evt->ecode)
      {
        	case EVT_BLUE_GATT_READ_PERMIT_REQ:
		{
          		read_permit_req = (aci_gatt_read_permit_req_event_rp0*)blue_evt->data;
			if(read_permit_req->Attribute_Handle == (aTemplateContext.TemplateReadClientToServerCharHdle + 1))
			{			
				memset(MsgResponse, 0x22, 87);
				ReadCount++;
		              HAL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_PIN);	
				(void)aci_gatt_allow_read(read_permit_req->Connection_Handle);	
				#if 1
				aci_gatt_update_char_value(aTemplateContext.TemplateSvcHdle,
				                                            aTemplateContext.TemplateReadClientToServerCharHdle,
				                                            0, /* charValOffset */
				                                            87, /* charValueLen */
				                                            (uint8_t *) MsgResponse);	
				 return_value = SVCCTL_EvtNotAck;
				#endif
			}
			break;
        	}

for example: See the code snipped below that I worked and found useful:

View solution in original post

5 REPLIES 5
Remi QUINTIN
ST Employee

​You may have a look at  the blood presure project  here:

STM32Cube_FW_WB_V1.5.0\Projects\P-NUCLEO-WB55.Nucleo\Applications\BLE\BLE_Peripheral_Lite

The related characteristic has a READ property.

JSHAR.1890
Associate II

Read request must always be completed with

(void)aci_gatt_allow_read(read_permit_req->Connection_Handle);

 switch(event_pckt->evt)
  {
    case EVT_VENDOR:
    {
      blue_evt = (evt_blue_aci*)event_pckt->data;
     
      switch(blue_evt->ecode)
      {
        	case EVT_BLUE_GATT_READ_PERMIT_REQ:
		{
          		read_permit_req = (aci_gatt_read_permit_req_event_rp0*)blue_evt->data;
			if(read_permit_req->Attribute_Handle == (aTemplateContext.TemplateReadClientToServerCharHdle + 1))
			{			
				memset(MsgResponse, 0x22, 87);
				ReadCount++;
		              HAL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_PIN);	
				(void)aci_gatt_allow_read(read_permit_req->Connection_Handle);	
				#if 1
				aci_gatt_update_char_value(aTemplateContext.TemplateSvcHdle,
				                                            aTemplateContext.TemplateReadClientToServerCharHdle,
				                                            0, /* charValOffset */
				                                            87, /* charValueLen */
				                                            (uint8_t *) MsgResponse);	
				 return_value = SVCCTL_EvtNotAck;
				#endif
			}
			break;
        	}

for example: See the code snipped below that I worked and found useful:

Exactly where i was looking for, thanks!

BScha.2
Associate

Thanks, thats it...... and my Problem is past now ....

Hello,

I just read your post on how to send message usi g BLE in STM32. Can you please help me know where I can include my alue so that I may be able to send using BLE. Thank you in advance.

Regards,

M.K