How to use the BLE library to scan for iBeacon signals

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
shun_26
Level 1
Level 1
First like given First reply posted First question asked

I want to receive the advertising signal of the surrounding iBeacon terminals, but when I execute wiced_bt_ble_observe(WICED_FALSE, 0, obv_callback), the information of the connected BT module (MAC address and advertising signal) is output.

The questions are summarized below.
When using the wiced_bt_ble_observe function,
- Why is the information of its own BT module (MAC address and advertising signal) output?
- Why is it scanned when the first argument is WICED_FALSE?

Also, if you have an example of using the wiced_bt_ble_observe function to receive the iBeacon device's advertised signal, I would appreciate it if you could provide the source code or project file.

<Development environment>
- Integrated development environment
 - STM32CubeMX ver.6.5.0
 - IAR Embedded workbench ver.9.30.1

- MCU: STM32H743XIH6
https://www.digikey.jp/en/products/detail/stmicroelectronics/STM32H743XIH6/7915906

- Wi-Fi/BT module: 1DX M.2 Module
https://www.embeddedartists.com/products/1dx-m-2-module/

- API
https://github.com/Infineon/bluetooth-freertos


<source code>
main.c (excerpt)

/* Configurate the Bluetotoh platform specific settings. */
cybt_platform_config_init(&bt_platform_config);


/* Initialize the Bluetooth controller and stack. */
wiced_result_t result = wiced_bt_stack_init(NULL, &wiced_bt_cfg_settings);
printf("%d\n", result);
-> 0 (WICED_BT_SUCCESS)


/* Get current scan state */
wiced_bt_ble_scan_type_t ble_scan_state;
ble_scan_state = wiced_bt_ble_get_current_scan_state();
printf("%d\n", ble_scan_state);
-> 2 (BTM_BLE_SCAN_TYPE_LOW_DUTY)


/* This function makes the device start or stop operating in the observer role. */
status_ble = wiced_bt_ble_observe(WICED_TRUE, 0, obv_callback);
printf("%d\n", status_ble);
-> 8105 (WRONG_MODE)

status_ble = wiced_bt_ble_observe(WICED_FALSE, 0, obv_callback);
printf("%d\n", status_ble);
-> 8100 (WICED_BT_PENDING)

status_ble = wiced_bt_ble_observe(WICED_TRUE, 0, obv_callback);
printf("%d\n", status_ble);
-> 8100 (WICED_BT_PENDING)

status_ble = wiced_bt_ble_observe(WICED_FALSE, 0, obv_callback);
-> MAC: 2B:88:A7:0C:8E:88: /* BT module's MAC Address */
-> Data: 94 D1 C4 9B 77 37 2D 85 19 CE E6 5C ...
printf("%d\n", status_ble);
-> 8100 (WICED_BT_PENDING)

0 Likes
7 Replies
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi @shun_26 ,

Can you share the complete project you are using to test this behavior?

Are you waiting for the BTM_ENABLED_EVT for the BT stack to be turned ON before initiating any BT functions? I is expected that you need to call the API  wiced_bt_ble_observe() in BTM_ENABLED_EVT  or after this event is received.

Example: https://github.com/Infineon/stm32-connectivity/blob/master/Projects/STM32H747I-DISCO/Applications/bl...

Regards,
Bragadeesh

Dear Bragadeesh

Thank you for answering my question and giving reference sites.

> Can you share the complete project you are using to test this behavior?
Unfortunately I can't share the complete project because I respond as an organization.

> Are you waiting for the BTM_ENABLED_EVT for the BT stack to be turned ON before initiating any BT functions? I is expected that you need to call the API  wiced_bt_ble_observe() in BTM_ENABLED_EVT  or after this event is received.
I tried using wiced_bt_stack_init() before wiced_bt_ble_observe(), but app_management_callback is not called and execution is terminated. Therefore, it is not possible to confirm that the BTM_ENABLED_EVT for the BT stack to be turned ON before initiating any BT functions. (The return value of wiced_bt_stack_init is "0".)

Is there somthing wrong how to use wiced_bt_stack_init()?

<source code>
wiced_result_t  result = wiced_bt_stack_init(app_management_callback, &wiced_bt_cfg_settings);
printf("%d\n", result);
 -> 0(WICED_SUCCESS)

Regards,
Shun

0 Likes
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi @shun_26 

If it is not possible to share the entire project, can you try sending us only the relevant portion of the code or the C file containing BT operations?

Did you check the sample project I sent you? Can you try using the stm-connectivity package and the run the BLE example project associated with it?

https://github.com/Infineon/stm32-connectivity

Regards,
Bragadeesh
0 Likes
lock attach
Attachments are accessible only for community members.

Dear Bragadeesh,

I share the relevant portion of the C file containing BT operations. If any information is missing, please let me know.

I checked the sample project you sent me. I try using the stm-connectivity package, but I didn't work.
I haven't fully understood how to use the BLE sample project yet. Continue learning to understand the project.

Regards,
Shun

0 Likes
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi @shun_26 ,

Your source code is missing several settings:

1. I do not see any initialization code for STM host. This includes initializing the UART interface that is required for communication between the STM host and the controller.

2. Btstack and the porting layer is based on RTOS and can not be used with out it. You have to initialize the RTOS environment and start your scheduler to get the btstack up and running.

Please take a look at the examples given in the stm-connectivity package to properly configure the STM host, RTOS environment, btstack and the porting layer

https://github.com/Infineon/stm32-connectivity/tree/master/Projects/STM32H747I-DISCO/Applications/bl...

Regards,
Bragadeesh
0 Likes

Dear Bragadeesh,

> 1. I do not see any initialization code for STM host. This includes initializing the UART interface that is required for communication between the STM host and the controller.

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_LPTIM1_Init();
MX_UART4_Init();
MX_USART1_UART_Init();

Is this the code to initialize the UART interface?

 

2. Btstack and the porting layer is based on RTOS and can not be used with out it. You have to initialize the RTOS environment and start your scheduler to get the btstack up and running.

https://github.com/Infineon/stm32-connectivity/blob/master/Projects/STM32H747I-DISCO/Applications/bl...

Does it mean that the function used in application_start() in app.c is missing?
If you know the function specifically to initialize the RTOS environment and start your scheduler to get the btstack up and running, please tell me.

Regards,
Shun

 

 

0 Likes
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi @shun_26 ,

Please check the file for initializing UART and RTOS

https://github.com/Infineon/stm32-connectivity/blob/master/Projects/STM32H747I-DISCO/Applications/bl...

Also go through the user guide for configuring your host correctly 

https://github.com/Infineon/stm32-connectivity/blob/master/Documentation/STM32ConnectivityExpansionP...

Regards,
Bragadeesh
0 Likes