Skip to main content
AMuya.1
Associate II
May 9, 2024
Question

I cannot read a BLE characteristic on Bluetooth 5.0 but on Bluetooth 5.1 it work

  • May 9, 2024
  • 1 reply
  • 1279 views

Good day to all,
I'm having an issue with a BLE characteristic on the STM32WB55. I have a characteristic that is a read only (it doesn't notify or indicate), and currently, it is just a counter that increments every second. I'm running a P2Pserver, with 1 service and 3 characteristics.
When I read the characteristic with a client application on my desktop with BLE 5.1 it works (I also used my phone with BLE 5.1 and it also works).
When I try to read on my laptop with a BLE 5.0, it will only read the characteristic when the Bluetooth connects but after that doing a read doesn't work at all.

The only thing different is the Bluetooth version of my devices. Other than that I don't know what could be the cause.
If anyone has an idea on how to fix this issue please help, because I expect this simple application to be backward compatible to BLE 4.2.

I am using the most recent version of STM32cube and the most recent firmware package for my board.

Here is how I initialized the characteristic

 

 

 /**
 * P2P_State
 */
 COPY_P2P_STATE_UUID(uuid16.Char_UUID_128);
 ret = aci_gatt_add_char(aPeerToPeerContext.PeerToPeerSvcHdle,
 UUID_TYPE_128, &uuid16,
 0x02,
 CHAR_PROP_READ,
 ATTR_PERMISSION_NONE,
 GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP,
 0x10,
 CHAR_VALUE_LEN_CONSTANT,
 &(aPeerToPeerContext.P2PCommsStateHdle));
 if (ret != BLE_STATUS_SUCCESS)
 {
 APP_DBG_MSG(" Fail : aci_gatt_add_char command : P2PCOMMSSTATE, error code: 0x%x \n\r", ret);
 }
 else
 {
 APP_DBG_MSG(" Success: aci_gatt_add_char command : P2PCOMMSSTATE \n\r");
 }

 

 

The function P2PS_UpdateCounter() is called in main every 1 seconds.
and 
P2PS_STM_App_Update_Char(....), update the characteristics value. this function doesn't fail and finish succesffuly. 

 

 

void P2PS_UpdateCounter( void )
{
 static uint16_t ucMoreTimeCounter = 0;

 ucMoreTimeCounter++;

 if( P2P_Server_App_Context.Notification_Status )
	{
 P2PS_STM_App_Update_Char( P2P_STATE_CHAR_UUID, &ucMoreTimeCounter, 2 );
	}

 return;
}

tBleStatus P2PS_STM_App_Update_Char( uint16_t UUID, uint8_t *pPayload, uint16_t usLength )
{
 tBleStatus result = BLE_STATUS_INVALID_PARAMS;
 switch(UUID)
 {
 case P2P_STATE_CHAR_UUID:
 result = aci_gatt_update_char_value(aPeerToPeerContext.PeerToPeerSvcHdle,
 aPeerToPeerContext.P2PCommsStateHdle,
 0, /* charValOffset */
 usLength, /* charValueLen */
 (uint8_t *) pPayload);
 if (result != BLE_STATUS_SUCCESS)
 {
 APP_DBG_MSG(" Fail : aci_gatt_update_char_value STATE command, result : 0x%x \n\r", result);
 // printf(" Fail : aci_gatt_update_char_value STATE command, result : 0x%x \n\r", result);
 }
 else
 {
 APP_DBG_MSG(" Success: aci_gatt_update_char_value STATE command\n\r");
 // printf(" Success: aci_gatt_update_char_value STATE command\n\r");
 }
 break;

 default:
 break;
 }

 return result;
}/* end P2PS_STM_Init() */

 

 

And finally, In the function that handle ACI_GATT events below, on BLE5.1 when I do a read on the characteristic, I can see that the event ACI_GATT_READ_PERMIT_REQ_VSEVT_CODE  every single time I do a read but on BLE 5.0, this event doesn't get triggered. it only triggered when a client connects. 

 

 

static SVCCTL_EvtAckStatus_t PeerToPeer_Event_Handler(void *Event)
{
 SVCCTL_EvtAckStatus_t return_value;
 hci_event_pckt *event_pckt;
 evt_blecore_aci *blecore_evt;
 aci_gatt_attribute_modified_event_rp0 * attribute_modified;
 aci_gatt_read_permit_req_event_rp0 *read_req;
 aci_gatt_notification_complete_event_rp0 *notification_complete;

 P2PS_STM_App_Notification_evt_t Notification;

 return_value = SVCCTL_EvtNotAck;
 event_pckt = (hci_event_pckt *)(((hci_uart_pckt*)Event)->data);

 switch(event_pckt->evt)
 {
 case HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE:
 {
 blecore_evt = (evt_blecore_aci*)event_pckt->data;
 switch(blecore_evt->ecode)
 {
 case ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE:
 {
 ............
 }
 break;

 case ACI_GATT_READ_PERMIT_REQ_VSEVT_CODE :
 /* USER CODE BEGIN EVT_BLUE_GATT_READ_PERMIT_REQ_BEGIN */
 printf("BLE READ\n");
 /* USER CODE END EVT_BLUE_GATT_READ_PERMIT_REQ_BEGIN */
 read_req = (aci_gatt_read_permit_req_event_rp0*)blecore_evt->data;
 if (read_req->Attribute_Handle == (aPeerToPeerContext.P2PCommsStateHdle + 1))
 {
 return_value = SVCCTL_EvtAckFlowEnable;
 /*USER CODE BEGIN CUSTOM_STM_Service_1_Char_3_ACI_GATT_READ_PERMIT_REQ_VSEVT_CODE_1 */

 /*USER CODE END CUSTOM_STM_Service_1_Char_3_ACI_GATT_READ_PERMIT_REQ_VSEVT_CODE_1*/
 aci_gatt_allow_read(read_req->Connection_Handle);
 /*USER CODE BEGIN CUSTOM_STM_Service_1_Char_3_ACI_GATT_READ_PERMIT_REQ_VSEVT_CODE_2 */
 printf("BLE STATE\n");

 /*USER CODE END CUSTOM_STM_Service_1_Char_3_ACI_GATT_READ_PERMIT_REQ_VSEVT_CODE_2*/
 } /* if (read_req->Attribute_Handle == (aPeerToPeerContext.P2PCommsStateHdle + CHARACTERISTIC_VALUE_ATTRIBUTE_OFFSET))*/
 
 /* USER CODE BEGIN EVT_BLUE_GATT_READ_PERMIT_REQ_END */

 /* USER CODE END EVT_BLUE_GATT_READ_PERMIT_REQ_END */
 break;
 
 case ACI_GATT_NOTIFICATION_COMPLETE_VSEVT_CODE:
 {
 ...............
 break;
 }

 default:
 break;
 }
 }
 break; /* HCI_HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE_SPECIFIC */

 default:
 break;
 }

 return(return_value);
}/* end SVCCTL_EvtAckStatus_t */

 

 

 

1 reply

STTwo-32
Technical Moderator
June 2, 2024

Hello @AMuya.1 

Could you please add your .ioc file. 

Best Regards.

STTwo-32 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.