Skip to main content
fvela.1
Associate
May 12, 2022 11:43 AM UTC
Question

Hello, I am following the following tutorial: "STM32WB Getting Started Series: Part 12b, Lab. Receiving data from the phone." But I have a problem because I don't know how to evaluate the value sent by the mobile. I hope you can help me, thanks.

..

This topic has been closed for replies.

3 replies

Remy ISSALYS
ST Technical Moderator
May 18, 2022 12:27 PM UTC

Hello,

You can look the following wiki page which explain how to generate a Bluetooth® Low Energy (BLE) server custom application for STM32WB55RG MCU using STM32CubeMX software:

https://wiki.st.com/stm32mcu/wiki/Connectivity:STM32WB_BLE_STM32CubeMX

Extract of section 7.4 Code modification: User sections part for custom_app.c file which show how to recover the value send by the smartphone and turn on/off the led according to this value:

/* Functions Definition ------------------------------------------------------*/
void Custom_STM_App_Notification(Custom_STM_App_Notification_evt_t *pNotification)
{
 /* USER CODE BEGIN CUSTOM_STM_App_Notification_1 */
 
 /* USER CODE END CUSTOM_STM_App_Notification_1 */
 switch(pNotification->Custom_Evt_Opcode)
 {
 /* USER CODE BEGIN CUSTOM_STM_App_Notification_Custom_Evt_Opcode */
 
 /* USER CODE END CUSTOM_STM_App_Notification_Custom_Evt_Opcode */
 
 /* My_P2P_Server */
 case CUSTOM_STM_LED_C_READ_EVT:
 /* USER CODE BEGIN CUSTOM_STM_LED_C_READ_EVT */
 
 /* USER CODE END CUSTOM_STM_LED_C_READ_EVT */
 break;
 
 case CUSTOM_STM_LED_C_WRITE_NO_RESP_EVT:
 /* USER CODE BEGIN CUSTOM_STM_LED_C_WRITE_NO_RESP_EVT */
 APP_DBG_MSG("\r\n\r** CUSTOM_STM_LED_C_WRITE_NO_RESP_EVT \n");
 APP_DBG_MSG("\r\n\r** Write Data: 0x%02X %02X \n", pNotification->DataTransfered.pPayload[0], pNotification->DataTransfered.pPayload[1]);
 if(pNotification->DataTransfered.pPayload[1] == 0x01)
 {
 HAL_GPIO_WritePin(Blue_Led_GPIO_Port, Blue_Led_Pin, GPIO_PIN_SET); 
 }
 if(pNotification->DataTransfered.pPayload[1] == 0x00)
 {
 HAL_GPIO_WritePin(Blue_Led_GPIO_Port, Blue_Led_Pin, GPIO_PIN_RESET); 
 } 
 /* USER CODE END CUSTOM_STM_LED_C_WRITE_NO_RESP_EVT */
 break;

Best Regards

fvela.1
fvela.1Author
Associate
May 18, 2022 1:37 PM UTC
Hi,
I'm looking at the page but the characteristics are sent from the mobile, on this page it is not created in the same way as in the tutorial I followed thanks.
Remy ISSALYS
ST Technical Moderator
May 24, 2022 3:05 PM UTC

Hello,

In custom_stm.c file, try the following code according to youtube video:

case ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE:
{
 attribute_modified = (aci_gatt_attribute_modified_event_rp0*) blecore_evt->data;
 if (attribute_modified->Attr_Handle == (CustomContext.CustomMycharwriteHdle + CHARACTERISTIC_VALUE_ATTRIBUTE_OFFSET))
 {
 APP_DBG_MSG("C2 WRITE - LENGTH = %d \n", attribute_modified->Attr_Data_Length);
 APP_DBG_MSG("Reception : ");
 for (i = 0; i < attribute_modified->Attr_Data_Length; i++)
 {
 APP_DBG_MSG("Data[%x] = 0x%x ", i, attribute_modified->Attr_Data[i]);
 }
 APP_DBG_MSG(" \r\n");
 }
...

Best Regards