cancel
Showing results for 
Search instead for 
Did you mean: 

[BLE RSSI] Reading RSSI value uint8_t

Portilha
Associate II

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

17 REPLIES 17
Andrew Neil
Evangelist III

What does the documentation tell you?

Portilha
Associate II

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;

  

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
Evangelist III

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?

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.

_Joe_
ST Employee

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é

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 */
        }
...

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?

I am using the Firmware version 1.2.0, according to STM32CubeIDE. What do you mean by starting from a release app? I am using the BLE project examples provided by ST like P2PServer, P2PClient, etc.