Forums - iBeacon demo with QCA4020

3 posts / 0 new
Last post
iBeacon demo with QCA4020
chuckbrodeur
Profile picture
Join Date: 16 Aug 19
Location: Rhode Island
Posts: 15
Posted: Wed, 2019-09-25 04:33

Are there any demos (or libraries) that include support for iBeacon?
Thanks

  • Up0
  • Down0
c_rpedad
Profile picture
Join Date: 18 Jun 18
Location: San Jose
Posts: 317
Posted: Mon, 2019-09-30 17:06

We dont have any demo showing iBeacon support.
However, QCA4020 QAPIs support standard BLE protocol hence application developer can take care of implementation of iBeacon using application note from Apple.

  • Up0
  • Down0
drglennwolfe
Join Date: 23 Sep 19
Posts: 9
Posted: Tue, 2022-02-22 06:07

 

iBeacon code example below for anyone who cares...  you will need to replace elog() function with your own.  Dr. Wolfe


  qapi_BLE_HCI_DriverInformation_t driver_info;
  // some sort of helper macro to set driver_info structure
  QAPI_BLE_HCI_DRIVER_SET_COMM_INFORMATION(&driver_info,
    QAPI_BLE_DRIVER_STOPBITS,
    QAPI_BLE_DRIVER_BAUDRATE,
    QAPI_BLE_COMM_PROTOCOL_UART_E);

  ble_id = qapi_BLE_BSC_Initialize(&driver_info, 0);
  if (ble_id <= 0) { elog("ERROR: qapi_BLE_BSC_Initialize\r\n"); }

  char* host_version = qapi_BLE_BSC_Query_Host_Version();
  elog("ble version = ");
  elog(host_version);
  elog("\r\n");

  int8_t tx_power;
  qapi_BLE_BSC_GetTxPower(ble_id, 0, &tx_power);
  char buf[128];
  snprintf(buf, 128, "ble tx power default = %i\r\n", tx_power);
  elog(buf);

  tx_power = 64;
  status = qapi_BLE_BSC_SetTxPower(ble_id, 0, tx_power);
  if (status != QURT_EOK) { elog("ERROR: ble, qapi_BLE_BSC_SetTxPower\r\n"); }

  qapi_BLE_BSC_GetTxPower(ble_id, 0, &tx_power);
  snprintf(buf, 128, "ble tx power = %i\r\n", tx_power);
  elog(buf);

  qapi_BLE_BD_ADDR_t ble_mac_addr;
  qapi_BLE_GAP_Query_Local_BD_ADDR(ble_id, &ble_mac_addr);
  snprintf(buf, 128, "ble mac address = %02x:%02x:%02x:%02x:%02x:%02x\r\n",
    ble_mac_addr.BD_ADDR0,
    ble_mac_addr.BD_ADDR1,
    ble_mac_addr.BD_ADDR2,
    ble_mac_addr.BD_ADDR3,
    ble_mac_addr.BD_ADDR4,
    ble_mac_addr.BD_ADDR5);
  elog(buf);

  //https://en.wikipedia.org/wiki/IBeacon
  #define PACKET_SIZE (31)
  uint8_t data[PACKET_SIZE] = {
  //   0,   1,   2,   3,   4,   5,   6,   7,   8,
    0x02,0x01,0x06,0x1A,0xFF,0x00,0x4C,0x02,0x15, // bytes 0-8: ibeacon header
  //   9,  10,  11,  12,  13,  14,  15,  16,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      // bytes 9-24: uuid
  //  17,  18,  19,  20,  21,  22,  23,  24,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      // uuid
  //  25,  26,  27,  28,
    0xde,0xad,0xbe,0xef,                          // bytes 25-26: major, bytes 27-28: minor
  //            29,  30
    (uint8_t)(-60),0x00};                           // byte 29: dB@1m [-127:127], byte 30: padded zero


  status = qapi_BLE_GAP_LE_Set_Advertising_Data(ble_id, PACKET_SIZE, (qapi_BLE_Advertising_Data_t*)data);
  if (status != QURT_EOK) { elog("ERROR: ble, qapi_BLE_GAP_LE_Set_Advertising_Data\n"); }

  uint32_t user_callback_param = 0; // anything you want it to be, will be sent to callback

  qapi_BLE_GAP_LE_Advertising_Parameters_t advertising_params;
  qapi_BLE_GAP_LE_Connectability_Parameters_t connection_params;

  boolean_t enable_scan_response = 0;

  advertising_params.Advertising_Interval_Min = 100; // what should these be?
  advertising_params.Advertising_Interval_Max = 200; // what should these be?
  advertising_params.Advertising_Channel_Map = QAPI_BLE_HCI_LE_ADVERTISING_CHANNEL_MAP_DEFAULT;
  advertising_params.Scan_Request_Filter = QAPI_BLE_FP_NO_FILTER_E;
  advertising_params.Connect_Request_Filter = QAPI_BLE_FP_NO_FILTER_E;

  connection_params.Connectability_Mode = QAPI_BLE_LCM_NON_CONNECTABLE_E;
  connection_params.Own_Address_Type = QAPI_BLE_LAT_PUBLIC_E;
  connection_params.Direct_Address_Type = QAPI_BLE_LAT_PUBLIC_E;
  // pretty sure this is the mac address, see include/qapi/qapi_ble_btbtypes.h
  connection_params.Direct_Address.BD_ADDR0 = ble_mac_addr.BD_ADDR0;
  connection_params.Direct_Address.BD_ADDR1 = ble_mac_addr.BD_ADDR1;
  connection_params.Direct_Address.BD_ADDR2 = ble_mac_addr.BD_ADDR2;
  connection_params.Direct_Address.BD_ADDR3 = ble_mac_addr.BD_ADDR3;
  connection_params.Direct_Address.BD_ADDR4 = ble_mac_addr.BD_ADDR4;
  connection_params.Direct_Address.BD_ADDR5 = ble_mac_addr.BD_ADDR5;

  status = qapi_BLE_GAP_LE_Advertising_Enable(
    ble_id,
    enable_scan_response,
    &advertising_params,
    &connection_params,
    system_callback,
    user_callback_param);
  if (status != QURT_EOK) { elog("ERROR: ble, qapi_BLE_GAP_LE_Advertising_Enable\n"); }


 

 

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.