2022-03-31 05:13 AM
Hello,
I'm using STM32WB to scan bel beacons, i started from p2p_client example and modified it to scan all types of beacons it shows all close devices, their MAC address and RSSI power, but i want to show more beacons info like beacon name, type, beacon temperture, etc.
Can anyone please tell me what to add in my code so that i can get all the beacons information?
static void BLE_UserEvtRx( void * pPayload );
static void Ble_Hci_Gap_Gatt_Init(void);
static const uint8_t* BleGetBdAddress( void );
void Scan_Request( void );
void APP_BLE_Init( void )
{
Ble_Tl_Init( );
UTIL_LPM_SetOffMode(1 << CFG_LPM_APP_BLE, UTIL_LPM_DISABLE);
UTIL_SEQ_RegTask( 1<<CFG_TASK_HCI_ASYNCH_EVT_ID,
UTIL_SEQ_RFU,hci_user_evt_proc);
if (SHCI_C2_BLE_Init( &ble_init_cmd_packet ) != SHCI_Success)
{
Error_Handler();
}
Ble_Hci_Gap_Gatt_Init();
SVCCTL_Init();
BleApplicationContext.Device_Connection_Status = APP_BLE_IDLE;
P2PC_APP_Init();
return;
}
SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt )
{
hci_event_pckt *event_pckt;
evt_le_meta_event *meta_evt;
hci_le_advertising_report_event_rp0 * le_advertising_event;
event_pckt = (hci_event_pckt*) ((hci_uart_pckt *) pckt)->data;
uint8_t result;
uint8_t event_type, event_data_size;
uint8_t adtype, adlength;
switch (event_pckt->evt)
{
case HCI_LE_META_EVT_CODE:
{
meta_evt = (evt_le_meta_event*) event_pckt->data;
switch (meta_evt->subevent)
{
case HCI_LE_ADVERTISING_REPORT_SUBEVT_CODE:
{
uint8_t *adv_report_data;
le_advertising_event = (hci_le_advertising_report_event_rp0 *) meta_evt->data;
event_type = le_advertising_event->Advertising_Report[0].Event_Type;
event_data_size = le_advertising_event->Advertising_Report[0].Length_Data;
adv_report_data = (uint8_t*)(&le_advertising_event->Advertising_Report[0].Length_Data)+1;
if (event_type == ADV_IND )
{
int8_t RSSI;
RSSI = (int8_t)*(uint8_t*) (adv_report_data + le_advertising_event-
>Advertising_Report[0].Length_Data);
if(RSSI>=(-65))//filter here by RSSI
{
printf("MAC : %x:%x:%x:%x:%x:%x"
,le_advertising_event->Advertising_Report[0].Address[5]
,le_advertising_event->Advertising_Report[0].Address[4]
,le_advertising_event->Advertising_Report[0].Address[3]
,le_advertising_event->Advertising_Report[0].Address[2]
,le_advertising_event->Advertising_Report[0].Address[1]
,le_advertising_event->Advertising_Report[0].Address[0]);
printf(" RSSI= %d\r\n",RSSI);
}
}
}
break;
default:
break;
}
}
break; /* HCI_LE_META_EVT_CODE */
default:
break;
}
return (SVCCTL_UserEvtFlowEnable);
}
void APP_BLE_Key_Button1_Action(void)
{
UTIL_SEQ_RegTask( 1<<CFG_TASK_START_SCAN_ID, UTIL_SEQ_RFU, Scan_Request);
UTIL_SEQ_SetTask(1 << CFG_TASK_START_SCAN_ID, CFG_SCH_PRIO_0);
}
static void Ble_Tl_Init( void )
{
HCI_TL_HciInitConf_t Hci_Tl_Init_Conf;
Hci_Tl_Init_Conf.p_cmdbuffer = (uint8_t*)&BleCmdBuffer;
Hci_Tl_Init_Conf.StatusNotCallBack = BLE_StatusNot;
hci_init(BLE_UserEvtRx, (void*) &Hci_Tl_Init_Conf);
return;
}
static void Ble_Hci_Gap_Gatt_Init(void){
uint8_t role;
uint16_t gap_service_handle, gap_dev_name_char_handle, gap_appearance_char_handle;
const uint8_t *bd_addr;
uint32_t srd_bd_addr[2];
uint16_t appearance[1] = { BLE_CFG_GAP_APPEARANCE };
/*HCI Reset to synchronise BLE Stack*/
hci_reset();
bd_addr = BleGetBdAddress();
aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET,
CONFIG_DATA_PUBADDR_LEN,
(uint8_t*) bd_addr);
srd_bd_addr[1] = 0x0000ED6E;
srd_bd_addr[0] = LL_FLASH_GetUDN( );
aci_hal_write_config_data( CONFIG_DATA_RANDOM_ADDRESS_OFFSET, CONFIG_DATA_RANDOM_ADDRESS_LEN, (uint8_t*)srd_bd_addr );
aci_hal_write_config_data( CONFIG_DATA_IR_OFFSET, CONFIG_DATA_IR_LEN, (uint8_t*)BLE_CFG_IR_VALUE );
aci_hal_write_config_data( CONFIG_DATA_ER_OFFSET, CONFIG_DATA_ER_LEN, (uint8_t*)BLE_CFG_ER_VALUE );
aci_hal_set_tx_power_level(1, CFG_TX_POWER);
aci_gatt_init();
role = 0;
#if (BLE_CFG_PERIPHERAL == 1)
role |= GAP_PERIPHERAL_ROLE;
#endif
#if (BLE_CFG_CENTRAL == 1)
role |= GAP_CENTRAL_ROLE;
#endif
if (role > 0)
{
const char *name = "P2P_C";
aci_gap_init(GAP_OBSERVER_ROLE|GAP_PERIPHERAL_ROLE, 0,//here
APPBLE_GAP_DEVICE_NAME_LENGTH,
&gap_service_handle, &gap_dev_name_char_handle, &gap_appearance_char_handle);
}
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.ioCapability = CFG_IO_CAPABILITY;
aci_gap_set_io_capability(BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.ioCapability);
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.mitm_mode = CFG_MITM_PROTECTION;
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.encryptionKeySizeMin
= CFG_ENCRYPTION_KEY_SIZE_MIN;
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.encryptionKeySizeMax
= CFG_ENCRYPTION_KEY_SIZE_MAX;
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.Use_Fixed_Pin =
CFG_USED_FIXED_PIN;
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.Fixed_Pin =
CFG_FIXED_PIN;
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.bonding_mode =
CFG_BONDING_MODE;
aci_gap_set_authentication_requirement(BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.bonding_mode, BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.mitm_mode,
CFG_SC_SUPPORT,
CFG_KEYPRESS_NOTIFICATION_SUPPORT, BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.encryptionKeySizeMin,
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.encryptionKeySizeMax,
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.Use_Fixed_Pin,
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.Fixed_Pin,
PUBLIC_ADDR
);
}
void Scan_Request( void )
{
tBleStatus result;
result = aci_gap_start_observation_proc(0xA0, 0x60, 0x00, 0x00, 0x00, 0x00);
if (result == BLE_STATUS_SUCCESS)
{
APP_DBG_MSG(" \r\n\r** START Scanning ** \r\n\r");
}
return;
}
const uint8_t* BleGetBdAddress( void )
{
uint8_t *otp_addr;
const uint8_t *bd_addr;
uint32_t udn;
uint32_t company_id;
uint32_t device_id;
udn = LL_FLASH_GetUDN();
if(udn != 0xFFFFFFFF)
{
company_id = LL_FLASH_GetSTCompanyID();
device_id = LL_FLASH_GetDeviceID();
bd_addr_udn[0] = (uint8_t)(udn & 0x000000FF);
bd_addr_udn[1] = (uint8_t)( (udn & 0x0000FF00) >> 8 );
bd_addr_udn[2] = (uint8_t)device_id;
bd_addr_udn[3] = (uint8_t)(company_id & 0x000000FF);
bd_addr_udn[4] = (uint8_t)( (company_id & 0x0000FF00) >> 8 );
bd_addr_udn[5] = (uint8_t)( (company_id & 0x00FF0000) >> 16 );
bd_addr = (const uint8_t *)bd_addr_udn;
}
else
{
otp_addr = OTP_Read(0);
if(otp_addr)
{
bd_addr = ((OTP_ID0_t*)otp_addr)->bd_address;
}
else
{
bd_addr = M_bd_addr;
}
}
return bd_addr;
}
2022-04-06 07:55 AM
Hello,
You have to parse advertising data (adv_report_data) to recover your data. Advertising data have the following structure (see BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 3, Part C) :
You have to use this with different offset:
adv_report_data = (uint8_t*)(&le_advertising_event->Advertising_Report[0].Length_Data)+offset;
A description of each AD type is available in this document:
Best Regards