cancel
Showing results for 
Search instead for 
Did you mean: 

How to use an STM32 as BLE client to connect to a 3rd party BLE server?

HGill.2
Associate II

I'm new to BLE and working on a project where I need to create a link from my STM32WB15 to a 3rd party IMU sensor. I have no access into the sensor, but I have the UUID's and advertisement data structure.

In STM32CubeProgrammer I set the parameters for the STM32 to be a client looking to link with a third party server. I believe I found the line's of code that direct me where it is pulling/finding the device UUID.

UTIL_SEQ_RegTask(1<<CFG_TASK_START_SCAN_ID, UTIL_SEQ_RFU, Scan_Request); UTIL_SEQ_RegTask(1<<CFG_TASK_CONN_DEV_1_ID, UTIL_SEQ_RFU, Connect_Request);

What I cant find is where in the files I can adjust which device it is searching for to input my sensor's UUID.

Any help would be great, thank you!

P.S. - I've been searching through header files, and other program files. I may be overlooking the exact line where I can manipulate the STM to search and connect with the IMU.

8 REPLIES 8
Remy ISSALYS
ST Employee

Hello,

You can look BLE_p2pClient example available in STM32CubeWB package. This example shows how to demonstrate Point-to-Point communication using BLE component (as GATT client). In this example, the central device (BLE_p2pClient) starts scanning when pressing the User button (SW1) then when BLE_p2pServer is detected, it automatically connects to it. In the code you can look in app_ble.c file into SVCCTL_App_Notification function in the case HCI_LE_ADVERTISING_REPORT_SUBEVT_CODE, that decode the advertising report.

Best Regards

HGill.2
Associate II

Hello and thank you for your reply!

In the "HCI_LE_ADVERTISING_REPORT_SUBEVT_CODE" case you mentioned, is this the location where I would be setting the UUID for the sensor my STM32WB15 Nucleo Board is trying to connect to?

Hello and thank you for your reply!

In the "HCI_LE_ADVERTISING_REPORT_SUBEVT_CODE" case you mentioned, is this the location where I would be setting the UUID for the sensor my STM32WB15 Nucleo Board is trying to connect to?

Remy ISSALYS
ST Employee

Hello,

If the advertising data of your sensor contains it UUID service, you should add a case on the AD type corresponding to the UUID service and check if the UUID value matches with the UUID expected.

Best Regards

I'm having a little trouble following along with this, where in the code (say the P2pClient code) would I be able to find this section to add the case statement? I assume this case statement you're suggesting to add will parse the advertising packet to confirm if it's the specified UUID we're looking to connect to?

Thanks again for your help in this!

Remy ISSALYS
ST Employee

Hello,

In app_ble.c file, see SVCCTL_App_Notification function:

case HCI_LE_ADVERTISING_REPORT_SUBEVT_CODE:
{
  uint8_t *adv_report_data;
  /* USER CODE BEGIN EVT_LE_ADVERTISING_REPORT */
  /* USER CODE END EVT_LE_ADVERTISING_REPORT */
  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;
 
  /* WARNING: be careful when decoding advertising report as its raw format cannot be mapped on a C structure.The data and RSSI values could not be directly decoded from the RAM using the data and RSSI field from hci_le_advertising_report_event_rp0 structure.              Instead they must be read by using offsets (please refer to BLE specification). RSSI = (int8_t)*(uint8_t*) (adv_report_data + le_advertising_event->Advertising_Report[0].Length_Data);
  */
  adv_report_data = (uint8_t*)(&le_advertising_event->Advertising_Report[0].Length_Data) + 1;
  k = 0;
 
  /* search AD TYPE 0x09 (Complete Local Name) */
  /* search AD Type 0x02 (16 bits UUIDS) */
  if (event_type == ADV_IND)
  {
    /* ISOLATION OF BD ADDRESS AND LOCAL NAME */
    while(k < event_data_size)
    {
      adlength = adv_report_data[k];
      adtype = adv_report_data[k + 1];
      switch (adtype)
      {
        case AD_TYPE_FLAGS: /* now get flags */
         /* USER CODE BEGIN AD_TYPE_FLAGS */
         /* USER CODE END AD_TYPE_FLAGS */
         break;
 
        .
        .
        .
        // ADD HERE THE CASE THE MANAGE AD TYPE FOR UUID
      }
    } /* end switch adtype */
    k += adlength + 1;
   } /* end while */
  } /* end if ADV_IND */
}
break;

Best Regards

Hello Again ISSALYS and thank you for your reply!

I have been lookin at that piece of code and I was also curious on where we can find the scan report data or where in memory on the device we can find the stored data?

As for the code, our device is from "___" company. With the following UUID's and Bluetooth Address:

�?Primary Service UUID = 6d071523-e3b8-4428-b7b6-b3f59c38b7bb

�? Data Characteristic UUID = 6d071524-e3b8-4428-b7b6-b3f59c38b7bb

�? Control Characteristic UUID = 6d071525-e3b8-4428-b7b6-b3f59c38b7bb

�? BLE Address: D7:E3:4B:FD:C6:4B


_legacyfs_online_stmicro_images_0693W00000bizMiQAI.pngHow would I amend the code to work with my device as the issue I'm coming across is it appears it's currently developed specifically for an ST device? I'm trying to develop a second case statement for a "device 2" which would (ideally) connect the client Nucleo board to my Foot Tracking Sensor.

Also, in the BLE definitions file, I noticed there are different GAP appearance values, should I leave it as unknown or change it to one of the location devices? (for example: location display device).

Thank you again for your help!

ICMosquera
Associate III

I want to know this, too. I captured my custom board (Gatt Server) advertisement inside the case statement. by modifying to this line.

...

else if(adlength >= 4 && adv_report_data[k + 2] == 0x12){
switch (adv_report_data[k + 3])

...

My problem now is I can't read the data sent by my custom board (Gatt Server) to the client board (Gatt Client) which is the nucleo. Is there I had missed where I can input the Service UUID?

 

Thanks,

I hope Remy can answer 🙂