Skip to main content
Associate III
August 18, 2025
Question

P2PClient connecting to Server Profile->Custom Template Unable to Get Characteristic

  • August 18, 2025
  • 1 reply
  • 267 views

Hello,

I have custom hardware with a WB55 on it that I'm trying to use as a client, I've chosen the P2PClient profile for this board.

I also have a Nucleo-WB55 board that is configured as my server, Server Profile with a Custom Template. The custom template has one characteristic that is a variable length CHAR_PROP_NOTIFY.

Modifying the app_ble.c and I can successfully connect to the Nucleo-WB55 board using the full name as can be seen in the code below.  

/* search AD TYPE 0x09 (Complete Local Name) */
/* search AD Type 0x02 (16 bits UUIDS) */
if (event_type == ADV_IND)
{
 /* ISOLATION OF BD ADDRESS AND LOCAL NAME */

 while(k < event_data_size)
 {
 adlength = adv_report_data[k];
 adtype = adv_report_data[k + 1];
 switch (adtype)
 {
 case AD_TYPE_FLAGS: /* now get flags */
 /* USER CODE BEGIN AD_TYPE_FLAGS */

 /* USER CODE END AD_TYPE_FLAGS */
 break;

 case AD_TYPE_TX_POWER_LEVEL: /* Tx power level */
 /* USER CODE BEGIN AD_TYPE_TX_POWER_LEVEL */
 	//int RSSI = (int8_t)*(uint8_t*) (adv_report_data + le_advertising_event->Advertising_Report[0].Length_Data);
 /* USER CODE END AD_TYPE_TX_POWER_LEVEL */
 break;

 case AD_TYPE_MANUFACTURER_SPECIFIC_DATA: /* Manufacturer Specific */
 /* USER CODE BEGIN AD_TYPE_MANUFACTURER_SPECIFIC_DATA */

 /* USER CODE END AD_TYPE_MANUFACTURER_SPECIFIC_DATA */
 if (adlength >= 7 && adv_report_data[k + 2] == 0x01)
 { /* ST VERSION ID 01 */
 APP_DBG_MSG("--- ST MANUFACTURER ID --- \n\r");
 switch (adv_report_data[k + 3])
 { /* Demo ID */
 case CFG_DEV_ID_P2P_SERVER1: /* End Device 1 */
 APP_DBG_MSG("-- SERVER DETECTED -- VIA MAN ID\n\r");
 BleApplicationContext.DeviceServerFound = 0x01;
 SERVER_REMOTE_ADDR_TYPE = le_advertising_event->Advertising_Report[0].Address_Type;
 SERVER_REMOTE_BDADDR[0] = le_advertising_event->Advertising_Report[0].Address[0];
 SERVER_REMOTE_BDADDR[1] = le_advertising_event->Advertising_Report[0].Address[1];
 SERVER_REMOTE_BDADDR[2] = le_advertising_event->Advertising_Report[0].Address[2];
 SERVER_REMOTE_BDADDR[3] = le_advertising_event->Advertising_Report[0].Address[3];
 SERVER_REMOTE_BDADDR[4] = le_advertising_event->Advertising_Report[0].Address[4];
 SERVER_REMOTE_BDADDR[5] = le_advertising_event->Advertising_Report[0].Address[5];
 break;

 default:
 break;
 }
 }
 break;

 case AD_TYPE_SERVICE_DATA: /* service data 16 bits */
 /* USER CODE BEGIN AD_TYPE_SERVICE_DATA */

 /* USER CODE END AD_TYPE_SERVICE_DATA */
 break;

 default:
 /* USER CODE BEGIN adtype_default */

 	case AD_TYPE_COMPLETE_LOCAL_NAME:
				{
					char name[adlength];
					for(int i = 0; i < adlength; i++)
					{
						name[i] = adv_report_data[k + 2 + i];
					}

					if (strstr(name, "My Custom Service") != NULL || strstr(name, "my custom service") != NULL)
					{
						BleApplicationContext.DeviceServerFound = 0x01;
						SERVER_REMOTE_ADDR_TYPE = le_advertising_event->Advertising_Report[0].Address_Type;
						SERVER_REMOTE_BDADDR[0] = le_advertising_event->Advertising_Report[0].Address[0];
						SERVER_REMOTE_BDADDR[1] = le_advertising_event->Advertising_Report[0].Address[1];
						SERVER_REMOTE_BDADDR[2] = le_advertising_event->Advertising_Report[0].Address[2];
						SERVER_REMOTE_BDADDR[3] = le_advertising_event->Advertising_Report[0].Address[3];
						SERVER_REMOTE_BDADDR[4] = le_advertising_event->Advertising_Report[0].Address[4];
						SERVER_REMOTE_BDADDR[5] = le_advertising_event->Advertising_Report[0].Address[5];
					}

					break;
				}

 /* USER CODE END adtype_default */
 break;
 } /* end switch adtype */
 k += adlength + 1;
 } /* end while */
} /* end if ADV_IND */

I set the DeviceServerFound and the SERVER_REMOTE_BDADDR values just like the case AD_TYPE_MANUFACTURER_SPECIFIC_DATA does.
While debugging the code, I expect the p2p_client_app.c Update_Service to be called so the characteristics can be found.  But in the following code, the aP2PClientContext[index].connHandle == 0, thus never setting the task.

case ACI_GATT_PROC_COMPLETE_VSEVT_CODE:
{
	aci_gatt_proc_complete_event_rp0 *pr = (void*)blecore_evt->data;
#if(CFG_DEBUG_APP_TRACE != 0)
 APP_DBG_MSG("-- GATT : ACI_GATT_PROC_COMPLETE_VSEVT_CODE \n");
 APP_DBG_MSG("\n");
#endif

 uint8_t index;

 index = 0;
 while((index < BLE_CFG_CLT_MAX_NBR_CB) && (aP2PClientContext[index].connHandle != pr->Connection_Handle))
 index++;

 if(index < BLE_CFG_CLT_MAX_NBR_CB)
 {

 UTIL_SEQ_SetTask( 1<<CFG_TASK_SEARCH_SERVICE_ID, CFG_SCH_PRIO_0);

 }
}

I can't figure out where the aP2PClientContext[index].connHandle is being set or what I'm missing to get a handle to my notify characteristic and turning it on to collect data from the Nucleo-WB55.

Any help would be greatly appreciated.

Kindest regards.

1 reply

kumaichiAuthor
Associate III
August 19, 2025

The only way I could get it to discover the server and characteristics was to change the values in the uuid.h file to the values defined in the server.

#define P2P_SERVICE_UUID (0x1234)
#define P2P_NOTIFY_CHAR_UUID (0x5678)

This causes an issue because every time there's a change to the .ioc file, the uuid.h is overwritten.  It doesn't appear that I can change the Event_Handler method inside p2p_client_app.c because that gets overwritten too.

Is there a correct way to do this so it continues to work after there is a change and the code is regenerated?

Kindest regards.

 

STTwo-32
Technical Moderator
September 22, 2025

Hello @kumaichi 

Defines will be forced to the configured or default values each regeneration of the code from the STM32CubeMX file.

Best Regards.

STTwo-32