2022-05-12 04:43 AM
2022-05-18 05:27 AM
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
2022-05-18 06:37 AM
2022-05-24 08:05 AM
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