cancel
Showing results for 
Search instead for 
Did you mean: 

How can I emulate the iBeacon scanner with a second BlueNRG-LP board?

JWill.8
Associate III

What I want to do is quite simple in theory :

1) Load the BLE Beacon application from the BlueNRG-LP Development Kit (DK) on the first BlueNRG-LP board and run

2) Verify with an Android BLE Scanner Phone app that the BLE Beacon app on the BlueNRG-LP is periodically updating (like RSSI values)

3) Start from some application in the DK (say the BLE_RC_LongRange project)

4) Modify this project source code to perform a passive scan on the 1M PHY (neutering connections as I am not interested in those for this experiment)

5) Override the hci_le_extended_advertising_report_event and hci_le_advertising_report_event callbacks recompile and place them in the project with breakpoints and run on the second BlueNRG-LP board

Result: Not hitting callback breakpoints on second board which I would expect because first board is constantly beaconing.

I left out a lot of details to keep the question as concise as I can.

My question is: Am I going about this the proper way and if not can you suggest two DK sample apps I can start from so I can slay this?

Thanks for any guidance..

JRW

11 REPLIES 11
JWill.8
Associate III

It seems like this user was trying to achieve (and had a bit more success than I did) the same.

https://community.st.com/s/question/0D53W000008kpV1SAI/how-to-get-a-detailed-scan-response

JWill.8
Associate III

I could REALLY use help from someone.

I have been trying with little success.

In a nutshell: I want to Broadcast a Beacon from the Beacon app in the SDK and detect and read it in a break-pointed callback on a second BlueNRG-LP board.

I am not interested in any "Connection" type scenario with GATT / known addresses.. etc. I simply want to "detect" the Beacon that is being Broadcast by the one BlueNRG-LP board.

After the standard initializations (System and BLE SYS CLock, BLE Stack, UART, BSP IO power save ,....etc,) here is my code snippet for the "scanning" board:

 uint8_t role = GAP_OBSERVER_ROLE | GAP_CENTRAL_ROLE;

 uint8_t bdaddr[] = {BD_ADDR_MASTER};

 uint8_t device_name[]={'N', 'o', 'd', 'e'};

 uint8_t ret;

 uint16_t service_handle, dev_name_char_handle, appearance_char_handle;

 /* Configure Public address */

 ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, bdaddr);

 if(ret != BLE_STATUS_SUCCESS) {

   PRINTF("aci_hal_write_config_data() failed: 0x%02x\r\n", ret);

   return ret;

 }

 /* Set the TX power */

 aci_hal_set_tx_power_level(0, OUTPUT_POWER_LEVEL);

 /* GAP Init */

 ret = aci_gap_init(role , 0, 0x07, 0x00, &service_handle, &dev_name_char_handle, &appearance_char_handle);

 if(ret){

   PRINTF("aci_gap_Init() failed: 0x%02x\r\n", ret);

   return ret;

 }

 /* Set the device name */

 ret = Gap_profile_set_dev_name(0, sizeof(device_name), device_name);

 if(ret){

   PRINTF("Gap_profile_set_dev_name() failed: 0x%02x\r\n", ret);

   return ret;

 }

 ret = aci_gap_set_scan_configuration(DUPLICATE_FILTER_ENABLED, SCAN_ACCEPT_ALL, LE_1M_PHY_BIT, ACTIVE_SCAN, SCAN_INTERVAL, SCAN_WINDOW);

 printf("Scan configuration for LE_1M_PHY: 0x%02X\n", ret);

 //ret = aci_gap_set_scan_configuration(DUPLICATE_FILTER_ENABLED, SCAN_ACCEPT_ALL, LE_CODED_PHY_BIT, ACTIVE_SCAN, SCAN_INTERVAL, SCAN_WINDOW); 

 //printf("Scan configuration for LE_CODED_PHY: 0x%02X\n", ret);

   ret = aci_gap_start_procedure(GAP_OBSERVATION_PROC /*GAP_GENERAL_DISCOVERY_PROC*/,LE_1M_PHY_BIT,0,0);

 printf("GAP Start Procedure for LE_1M_PHY: 0x%02X\n", ret);

 debounce_timer.callback = DebounceTimeoutCB;

 scanningLEDTimerHandle.callback = ScanningLEDTimeoutCB;

 writeTimerHandle.callback = writeTimeoutCB;

 statsTimerHandle.callback = statsTimeoutCB;

 return BLE_STATUS_SUCCESS;

.... and my callbacks:

void hci_le_extended_advertising_report_event(uint8_t Num_Reports,

                                             Extended_Advertising_Report_t Extended_Advertising_Report[])

{

   Extended_Advertising_Report_t * ptr = Extended_Advertising_Report;

   return;

}

void hci_le_advertising_report_event(uint8_t Num_Reports,

                                    Advertising_Report_t Advertising_Report[])

{

   return;

}

I had also tried explicitly enabling the events through the event mask mechanism:

   /* --- JRW Hopefully ticket out of purgatory */

 ret = hci_le_set_event_mask(LE_Event_Mask);

 if(ret)

 {

   PRINTF("hci_le_set_event_mask 0x%02X\n",ret);

 }

where event mask:

static uint8_t LE_Event_Mask[8]={

   HCI_LE_EVT_MASK_BYTE0_ADVERTISING_REPORT ,

   HCI_LE_EVT_MASK_BYTE1_EXTENDED_ADVERTISING_REPORT | HCI_LE_EVT_MASK_BYTE1_PHY_UPDATE_COMPLETE,

   0x00,

   0x00,

   0x00,

   0x00};

I cannot get the callbacks to fire for BlueNRG-LP (running the stock ST Micro SDK Beacon Demo)

Any suggestions? I just need a hint (other than give up) not the answer...

Naturally, after I hit the send for SOS button, I got it working...

EBen-
Associate II

Hi @JWill.8​ 

Same as you, I'm trying to receive data from a verified BLE Beacon app on another device.

I see that you got it working, could you please suggest which DK sample app you have used for the scanner?

If possible to share your source code for this it would be awesome, but any hint would be welcome, for a start entering the callback would be enough.

Thanks in advance for any guidance

Certainly. In a nutshell, here is what I did:

  • I am using 1M PHY everywhere
  • I was using two BlueNRG-LP boards:
    • One running modified version BLE LongRange server application (i.e., supplied the Beacon peripheral/server role)
    • One running a modified version of the BLE LongRange client application (i.e. central/client role)
  • I replaced (weak?) callback void hci_le_extended_advertising_report_event() in client. hci_le_advertising_report_event never was called with my setup.
  • I realized the callback was also being invoked from other physical Bluetooth sources other than the BlueNRG-LP so you may need to filter those rogue events.
  • In the client I made use of the Data element in the Extended_Advertising_Report_t struct passed into the void hci_le_extended_advertising_report_event() callback and used it to filter rogue events
  • In the client I use the GAP_OBSERVER_ROLE in aci_gap_init
  • In the client I use GAP_OBSERVATION_PROC in aci_gap_start_procedure
  • In the server I use GAP_MODE_GENERAL_DISCOVERABLE in aci_gap_set_advertising_configuration
  • In the server I enable advertising using ENABLE in aci_gap_set_advertising_enable

Does that help?..

JRW

EBen-
Associate II

Thanks for your fast response!!

Unfortunately I just realized that your using BlueNRG-LP while I'm using BueNRG-1. Probably there's a lot of similarity between them so I'll try to use your guidance, but I'll have to dive deeper into it because there's no 'BLE LongRange' example in the BlueNRG1 DK.

in any case, many thanks for your help! I really appreciate the time you invested in replying my msg

JWill.8
Associate III

Sure thing. FYI, there really is nothing special about the BLE LongRange example code, as most of the coded PHY and GATT portions I commented out anyway. It is just a two-radio starting point I picked at random. It was really the GAP portion of that sample code I was interested in. Also, I believe you can download it from here:https://www.st.com/en/embedded-software/stsw-bnrglp-dk.html. Finally, much of the code is already attached to this ticket earlier. If you don't make any progress, I can attach further code snippets but you should be able to start from any two-radio sample code in the BlueNRG1 DK. Or perhaps I can look at the BlueNRG1 DK.....

Update: I just took a brief look at the BlueNRG-1 DK and now I see what you are up against. The aci_gap API's differ between the two platforms, unfortunately. So it is not as easy as I made it sound earlier (sorry about that). I think the BLE_MS_Formula example under Project->BLE_Examples in the BlueNRG-1 DK may be the best starting point.... And BLE_Beacon under Project->BLE_Examples

So I'm using this one  BLE_MS_Formula as a starting point, and it proved as a good guess because I've managed to receive some advertising data.

Thank you @JWill.8​ for your help!

Actually I was expecting no reply, this community isn't very active as it seems from other inquiries. So your help was much above expectations!

many thanks :folded_hands: :clinking_beer_mugs: