cancel
Showing results for 
Search instead for 
Did you mean: 

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 blutooth devices, their MAC and RSSI power, but i want to show more beacons info like name, type, temperture..

BLiwa.1
Associate II
#define APPBLE_GAP_DEVICE_NAME_LENGTH 7
#define BD_ADDR_SIZE_LOCAL    6
#if OOB_DEMO != 0 
#define LED_ON_TIMEOUT            (0.005*1000*1000/CFG_TS_TICK_VAL) /**< 5ms */
#endif 
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t BleCmdBuffer;
static const uint8_t M_bd_addr[BD_ADDR_SIZE_LOCAL] =
    {
        (uint8_t)((CFG_ADV_BD_ADDRESS & 0x0000000000FF)),
        (uint8_t)((CFG_ADV_BD_ADDRESS & 0x00000000FF00) >> 8),
        (uint8_t)((CFG_ADV_BD_ADDRESS & 0x000000FF0000) >> 16),
        (uint8_t)((CFG_ADV_BD_ADDRESS & 0x0000FF000000) >> 24),
        (uint8_t)((CFG_ADV_BD_ADDRESS & 0x00FF00000000) >> 32),
        (uint8_t)((CFG_ADV_BD_ADDRESS & 0xFF0000000000) >> 40)
    };
static uint8_t bd_addr_udn[BD_ADDR_SIZE_LOCAL];
static const uint8_t BLE_CFG_IR_VALUE[16] = CFG_BLE_IRK;
static const uint8_t BLE_CFG_ER_VALUE[16] = CFG_BLE_ERK;
tBDAddr SERVER_REMOTE_BDADDR;
P2PC_APP_ConnHandle_Not_evt_t handleNotification;
PLACE_IN_SECTION("BLE_APP_CONTEXT") static BleApplicationContext_t BleApplicationContext;
#if OOB_DEMO != 0
APP_BLE_p2p_Conn_Update_req_t APP_BLE_p2p_Conn_Update_req;
#endif
uint8_t disp_filter = 0;
static void BLE_UserEvtRx( void * pPayload );
static void BLE_StatusNot( HCI_TL_CmdStatus_t status );
static void Ble_Tl_Init( void );
static void Ble_Hci_Gap_Gatt_Init(void);
static const uint8_t* BleGetBdAddress( void );
void Scan_Request( void );
static void Connect_Request( void );
static void Switch_OFF_GPIO( 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;
  hci_disconnection_complete_event_rp0 *cc = (void *) event_pckt->data;
  uint8_t result;
  uint8_t event_type, event_data_size;
  int k = 0;
  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 : %02x:%02x:%02x:%02x:%02x:%02x"
                                    ,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);
} 
void APP_BLE_Key_Button2_Action(void)
{
	 disp_filter = !disp_filter;
}
void APP_BLE_Key_Button3_Action(void)
{
}
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;
}

0693W00000LvyRZQAZ.pngDo anyone have an idea please, what should i add to the code so that i can get all beacon information

1 REPLY 1
Remy ISSALYS
ST Employee

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) :

0693W00000Lx7I9QAJ.pngYou 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:

https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Generic%20Access%20Profile.pdf

Best Regards