cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB Notification doesn't seem to be working?

SWenn.1
Senior III

Hello 

I am using the following to try and get a notification from an STM32WB Nucleo server to my phone the client but cannot get it to work.

BLE Notifications ---- ST Micro video 

I compile and can see the two characteristics on my phone but when I push the button on the board my phone never updates with anything.  I have tried ST Toolbox and nRF Connect and neither works.

I have attached my project pdf file from CubeMX.  This project was built on a test that does Pairing and Bonding with Pairing required only on certain characteristics from the Product service.  After this was working successfully I added the STATUS service (page 18) which is pretty similar to the video. 

The difference is the VALVE characteristic has permission set to:

ATTR_PERMISSION_AUTHEN_WRITE = YES

and GATT event set to :

GATT_NOTIFY_WRITE_REQ_AND_WAIT_FOR_APPL_RESP = YES

The second characteristic is the NOTIFICATION which the video is based off of (see page 18 of the pdf).

Can anyone please share some light as to what I might try?

Thank you

Steve

3 REPLIES 3
Dsarychev
Associate

Hi,

Had the same issue for a week. In my case the "if" statement was the culprit. It is generated in a way, that it never executes the "Custom_Button_c_Update_Char" function.

In my case the name of the service is "myService" and the name of my characteristic is "Button_c"

Try to modify the generated code in the "custom_app.c" file like so:

 

/* myService */
void Custom_Button_c_Update_Char(void) /* Property Read */
{
uint8_t updateflag = 0;

/* USER CODE BEGIN Button_c_UC_1*/
Custom_STM_App_Update_Char(CUSTOM_STM_BUTTON_C, (uint8_t *)UpdateCharData);
/* USER CODE END Button_c_UC_1*/

if (updateflag != 0)
{
Custom_STM_App_Update_Char(CUSTOM_STM_BUTTON_C, (uint8_t *)UpdateCharData);
}

/* USER CODE BEGIN Button_c_UC_Last*/

/* USER CODE END Button_c_UC_Last*/
return;
}

This way you avoid code modification everytime you re-generate your code.

 

Also, I can't seem to find the attachment you mentioned.

STTwo-32
ST Employee

Hello @SWenn.1 

I suggest you take a look at this WIKI. It should be Helpful. 

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.

Yasin Yelkovan
Associate III

Hi SWenn,

I had the same problem with this video tutorial, so I made some changes and share them below:

 

 

** custom_app.c **
1)Add these variables: 
/* USER CODE BEGIN PV */
uint8_t notifyStatus = 0;
uint8_t button1Status = 0;
/* USER CODE END PV */

2) Modify the fuction:
/* USER CODE BEGIN PFP */
void myTask(void){
	if(button1Status != HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin)){

		button1Status = HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin);
		NotifyCharData[0] = button1Status;
		Custom_Char2_Send_Notification();
	}
	UTIL_SEQ_SetTask(1<<CFG_TASK_MY_TASK, CFG_SCH_PRIO_0);
}
/* USER CODE END PFP */

3) Modify the fuction:
/* 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 */

    /* Service_1 */
    case CUSTOM_STM_CHAR1_WRITE_EVT:
      /* USER CODE BEGIN CUSTOM_STM_CHAR1_WRITE_EVT */

      /* USER CODE END CUSTOM_STM_CHAR1_WRITE_EVT */
      break;

    case CUSTOM_STM_CHAR2_NOTIFY_ENABLED_EVT:
      /* USER CODE BEGIN CUSTOM_STM_CHAR2_NOTIFY_ENABLED_EVT */
    	notifyStatus = 1;
      /* USER CODE END CUSTOM_STM_CHAR2_NOTIFY_ENABLED_EVT */
      break;

    case CUSTOM_STM_CHAR2_NOTIFY_DISABLED_EVT:
      /* USER CODE BEGIN CUSTOM_STM_CHAR2_NOTIFY_DISABLED_EVT */
    	notifyStatus = 0;
      /* USER CODE END CUSTOM_STM_CHAR2_NOTIFY_DISABLED_EVT */
      break;

    case CUSTOM_STM_NOTIFICATION_COMPLETE_EVT:
      /* USER CODE BEGIN CUSTOM_STM_NOTIFICATION_COMPLETE_EVT */

      /* USER CODE END CUSTOM_STM_NOTIFICATION_COMPLETE_EVT */
      break;

    default:
      /* USER CODE BEGIN CUSTOM_STM_App_Notification_default */

      /* USER CODE END CUSTOM_STM_App_Notification_default */
      break;
  }
  /* USER CODE BEGIN CUSTOM_STM_App_Notification_2 */

  /* USER CODE END CUSTOM_STM_App_Notification_2 */
  return;
}

4)Modify the fuction:
void Custom_Char2_Send_Notification(void) /* Property Notification */
{
  uint8_t updateflag = 0;

  /* USER CODE BEGIN Char2_NS_1*/
  updateflag = notifyStatus;
  /* USER CODE END Char2_NS_1*/

  if (updateflag != 0)
  {
    Custom_STM_App_Update_Char(CUSTOM_STM_CHAR2, (uint8_t *)NotifyCharData);
  }

  /* USER CODE BEGIN Char2_NS_Last*/

  /* USER CODE END Char2_NS_Last*/

  return;
}