2026-01-12 3:33 AM
Hello.
I got my hands on a wba55cg nucleo board and i'm currently studying about ble.
I want to create a BLE Beacon that changes its adv_data whenever a user presses one of the button. From messing around using the p2p_server and beacon st examples, i implemented the following steps:
1) Create a task that updates the adv_data and register it to the ble back ground sequencer. Added the following line in app_conf.h
CFG_TASK_ADV_DATA_UPDATE,
2)Set my device as eddystone uuid. Again added the following line in app_conf.h
#define CFG_BEACON_TYPE (CFG_EDDYSTONE_UID_BEACON_TYPE )
3)On app_ble_init in app_ble.c registered a function to handle my task
UTIL_SEQ_RegTask(1U << CFG_TASK_ADV_DATA_UPDATE, UTIL_SEQ_RFU,Ble_adv_data_update);
4) Implemented the adv_data_update_function inside app_ble.c
static void Ble_adv_data_update(void)
{
const char str1[] = "ESS";
const char str2[] = "TODAY IS 11";
uint8_t adv_data[31];
uint8_t len = 0;
/* --- FLAGS --- */
adv_data[len++] = 2; // length
adv_data[len++] = AD_TYPE_FLAGS;
adv_data[len++] =
FLAG_BIT_LE_GENERAL_DISCOVERABLE_MODE |
FLAG_BIT_BR_EDR_NOT_SUPPORTED;
/* --- MANUFACTURER SPECIFIC DATA --- */
adv_data[len++] = 1 + 2 + sizeof(str1) - 1 + sizeof(str2) - 1;
adv_data[len++] = AD_TYPE_MANUFACTURER_SPECIFIC_DATA;
/* Company ID (example, use your own if you have one) */
adv_data[len++] = 0xE5;
adv_data[len++] = 0x69;
/* Payload: "ESS" */
memcpy(&adv_data[len], str1, sizeof(str1) - 1);
len += sizeof(str1) - 1;
/* Payload: "TODAY IS 11" */
memcpy(&adv_data[len], str2, sizeof(str2) - 1);
len += sizeof(str2) - 1;
/* --- Update advertising data --- */
aci_gap_update_adv_data(len, adv_data);
}
5) Tired to reister a gpio pin, that the user button is connected to as an exti source on app_entry and push the adv_update task on its callback (can't access .ioc file due to version incompatibility)
static void Custom_gpio_init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; // button press
GPIO_InitStruct.Pull = GPIO_PULLUP; // external pull-up/down?
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}
//Called above fyunction inside MX_APPE_INIT
void EXTI15_10_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
}
void HAL_GPIO_EXTI_Callback( uint16_t GPIO_Pin )
{
switch (GPIO_Pin)
{
case GPIO_PIN_13:
UTIL_SEQ_SetTask(1U << CFG_TASK_ADV_DATA_UPDATE, CFG_SEQ_PRIO_0);
break;
default:
break;
}
}
Any advice would be more than welcome