Skip to main content
Associate II
February 12, 2024
Question

[BLE RSSI] Reading RSSI value uint8_t

  • February 12, 2024
  • 17 replies
  • 4991 views

Hello, I am working with STM32WBA52CG as a central and I want to read the RSSI from the incoming advertising packets. The RSSI value should be a negative value in dBm, however it is defined as uint8_t in the AdvertisingReport_t structure. Can someone explain me how to get the correct RSSI value? I am getting the values shown on the terminal below.

... 
}
 bleAppContext.BleApplicationContext_legacy.connectionHandle = p_conn_complete->Connection_Handle;

 GATT_CLIENT_APP_Set_Conn_Handle(0, p_conn_complete->Connection_Handle);

 /* USER CODE BEGIN HCI_EVT_LE_CONN_COMPLETE */

 /* USER CODE END HCI_EVT_LE_CONN_COMPLETE */
 break; /* HCI_LE_CONNECTION_COMPLETE_SUBEVT_CODE */
 }
 case HCI_LE_ADVERTISING_REPORT_SUBEVT_CODE:
 {
 hci_le_advertising_report_event_rp0 *p_adv_report;
 p_adv_report = (hci_le_advertising_report_event_rp0 *) p_meta_evt->data;
 UNUSED(p_adv_report);
 /* USER CODE BEGIN HCI_EVT_LE_ADVERTISING_REPORT */
 uint8_t rssi = p_adv_report->Advertising_Report[0].RSSI;
 LOG_INFO_APP("RSSI from struct: %d , ", rssi);
 /* USER CODE END HCI_EVT_LE_ADVERTISING_REPORT */
 break; /* HCI_LE_ADVERTISING_REPORT_SUBEVT_CODE */
 }
...

 Screenshot from 2024-02-12 10-41-02.png

This topic has been closed for replies.

17 replies

Andrew Neil
Super User
February 12, 2024

What does the documentation tell you?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
PortilhaAuthor
Associate II
February 12, 2024

The RSSI parameter in the AdvertisingReport_t structure is defined in this way. It is defined as uint8_t but it should be a negative value.

 

 /**
 * RSSI (signed integer).
 * Units: dBm.
 * Values:
 * - 127: RSSI not available
 * - -127 ... 20
 */
 uint8_t RSSI;
} Advertising_Report_t;
PortilhaAuthor
Associate II
February 12, 2024

The RSSI parameter in the AdvertisingReport_t structure is defined in this way. It is defined as uint8_t but it should be a negative value.

... 
/**
 * RSSI (signed integer).
 * Units: dBm.
 * Values:
 * - 127: RSSI not available
 * - -127 ... 20
 */
 uint8_t RSSI;
} Advertising_Report_t;

  

Andrew Neil
Super User
February 12, 2024

As far as transporting it over the air, it's just a byte.

When it comes to using it, cast it to int8_t ?

Take a look a the chip documentation - does that give any clues?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
PortilhaAuthor
Associate II
February 12, 2024

If it is just a byte, a value such as 74 does not make sense. As per chip documentation there is no clear information about this RSSI value interpretation.

ST Technical Moderator
February 13, 2024

Hi Portilha 

In fact, the structures of the type "hci_le_advertising_report_event_rp0" mapped to the RAM buffer were not designed to do this.

For the RSSI, you need to use the following macro:
==>ble.h:


/* Exported macros -----------------------------------------------------------*/
/* -------------------------------- *
* [retrieved from ble_legacy file]
* Macro to get RSSI from advertising report #0.
* "p" must be a pointer to the event parameters buffer
* -------------------------------- */
#define HCI_LE_ADVERTISING_REPORT_RSSI_0(p) \
(*(int8_t*)((&((hci_le_advertising_report_event_rp0*)(p))-> \
Advertising_Report[0].Length_Data) + 1 + \
((hci_le_advertising_report_event_rp0*)(p))-> \
Advertising_Report[0].Length_Data))

==>app_ble.c :

int8_t rssi = HCI_LE_ADVERTISING_REPORT_RSSI_0(p_meta_evt->data);

Clarifications will be added to the code regarding this subject in the upcoming releases.

BR, Joé

PortilhaAuthor
Associate II
February 14, 2024

I have exported that macro to file "ble.h" and I am using it on the SVCCTL_App_Notification function in file "app_ble.c", however the RSSI value keeps returning 0 all the time. Can you clarify?

...
case HCI_LE_ADVERTISING_REPORT_SUBEVT_CODE:
 {
 hci_le_advertising_report_event_rp0 *p_adv_report;
 p_adv_report = (hci_le_advertising_report_event_rp0 *) p_meta_evt->data;
 UNUSED(p_adv_report);
 /* USER CODE BEGIN HCI_EVT_LE_ADVERTISING_REPORT */

 int8_t rssi = HCI_LE_ADVERTISING_REPORT_RSSI_0(p_meta_evt->data);

 LOG_INFO_APP("RSSI %d\r\n", rssi);

// parse_advData(&p_adv_report->Advertising_Report->Data, p_adv_report->Advertising_Report->Length_Data, p_adv_report->Advertising_Report->Length_Data,
// 		 	 	&p_adv_report->Advertising_Report->Address, rssi);

 /* USER CODE END HCI_EVT_LE_ADVERTISING_REPORT */
 break; /* HCI_LE_ADVERTISING_REPORT_SUBEVT_CODE */
 }
...
ST Technical Moderator
February 14, 2024

What version of MCU Package are you using? The v1.0.0?

Have you tried starting from a release app and only adding these modifications to it?

ST Technical Moderator
February 15, 2024

Ok perfect, I mean, have you tried starting from a new code (ex : p2pClient), without any modification except the macro to get the RSSI?

PortilhaAuthor
Associate II
February 15, 2024

Yes, I took the ST P2PClient with version 1.2.0 and I only added the following line codes:

APP_BLE_Init(void)

... 
/* USER CODE BEGIN APP_BLE_Init_2 */
 APP_BLE_Procedure_Gap_Central(PROC_GAP_CENTRAL_SCAN_START);
 /* USER CODE END APP_BLE_Init_2 */
...

SVCCTL_App_Notification(void)

...
case HCI_LE_ADVERTISING_REPORT_SUBEVT_CODE:
 {
 hci_le_advertising_report_event_rp0 *p_adv_report;
 p_adv_report = (hci_le_advertising_report_event_rp0 *) p_meta_evt->data;
 UNUSED(p_adv_report);
 /* USER CODE BEGIN HCI_EVT_LE_ADVERTISING_REPORT */
 int8_t rssi = HCI_LE_ADVERTISING_REPORT_RSSI_0(p_meta_evt->data);
 LOG_INFO_APP("RSSI: %d\r\n", rssi);
 /* USER CODE END HCI_EVT_LE_ADVERTISING_REPORT */
 break; /* HCI_LE_ADVERTISING_REPORT_SUBEVT_CODE */
 }
...

 The RSSI just keeps returning 0. There must be some kind of bug on your library, is it possible to provide a fix or any kind of solution to read the RSSI value from incoming packets while the STM is working as a central?

ST Technical Moderator
February 15, 2024

The problem arises because you are using the examples from STM32WBA55 of release v1.2.0 while you have an STM32WBA52.
With the STM32WBA52 examples, which you can find in release v1.1.1, you should no longer encounter the RSSI problem after adding the previously given macro.

BR,
Joé

ST Technical Moderator
February 15, 2024

In the bottom of your screenshot, we can see that your project still uses v1.2.0.

PortilhaAuthor
Associate II
February 15, 2024

But how can I use the 1.1.1? I used the .ioc file in the Github link that you provided and it still generates 1.2.0 version on the project.