Skip to content

Accessing the BLE signal strength in the calling program. #1

@WPS12TA

Description

@WPS12TA

Feature Request: Add BLE RSSI (BLE Signal Strength) Access to calling program.

RadiaCode Library - BLE RSSI Patch

Status: TESTED AND WORKING
Date: March 2026
Compatible With: RadiaCode library by Markus Geiger (mkgeiger)

This patch adds RSSI (signal strength) access to the RadiaCode Arduino library.


What This Patch Does

Adds a getRSSI() method to access BLE signal strength from your RadiaCode device.

Returns:

  • -30 to -90 dBm: Connected (typical range)
  • -100: Not connected or error

Installation Instructions

You need to edit 4 files in your RadiaCode library folder:

Location: Documents/Arduino/libraries/RadiaCode/src/


FILE 1: BluetoothTransport.h

FIND the public section:

public:
    BluetoothTransport(const char* mac);
    virtual ~BluetoothTransport(void);
    virtual BytesBuffer execute(const uint8_t* request, size_t length) override;

ADD this line after the execute() line:

    int getRSSI();  // Get BLE signal strength

Result should look like:

public:
    BluetoothTransport(const char* mac);
    virtual ~BluetoothTransport(void);
    virtual BytesBuffer execute(const uint8_t* request, size_t length) override;
    int getRSSI();  // Get BLE signal strength

FILE 2: BluetoothTransport.cpp

SCROLL TO THE VERY END of the file (after the last function's closing brace)

ADD this complete function:

int BluetoothTransport::getRSSI() {
#ifdef BT_SUPPORT_ENABLED
    if (_peripheral) {
        BLEClient* pClient = (BLEClient*)_peripheral;
        if (pClient->isConnected()) {
            return pClient->getRssi();
        }
    }
#endif
    return -100;  // Not connected
}

FILE 3: RadiaCode.h

FIND the public section (around line 90):

    // Direct sensor reading methods
    float getTemperature(void);

ADD this line after getTemperature():

    int getRSSI();  // Get BLE signal strength in dBm

Result should look like:

    // Direct sensor reading methods
    float getTemperature(void);
    int getRSSI();  // Get BLE signal strength in dBm

FILE 4: RadiaCode.cpp

FIRST - Check the #include section at the top of the file.

MAKE SURE this line exists (add it if missing):

#include "BluetoothTransport.h"

THEN - SCROLL TO THE VERY END of the file (after the last function)

ADD this complete function:

int RadiaCode::getRSSI() {
    if (!_connection) {
        return -100;  // No connection
    }
    // Safe cast on ESP32 - _connection is always BluetoothTransport
    BluetoothTransport* bt = (BluetoothTransport*)_connection;
    return bt->getRSSI();
}

⚠️ Critical Notes

1. Add Functions at the END of Files

DO NOT add functions INSIDE other functions!

  • Always add at the END of .cpp files
  • Look for the last closing brace } of existing code
  • Add your new function AFTER that

2. Use C-Style Cast (Not dynamic_cast)

Arduino doesn't support RTTI, so use simple casting:

// ✅ CORRECT - C-style cast
BluetoothTransport* bt = (BluetoothTransport*)_connection;

// ❌ WRONG - dynamic_cast not supported
BluetoothTransport* bt = dynamic_cast<BluetoothTransport*>(_connection);

3. Include BluetoothTransport.h

Make sure RadiaCode.cpp includes the header:

#include "BluetoothTransport.h"

Usage in Your Sketch

After patching, you can use:

RadiaCode* radiacode = new RadiaCode(RADIACODE_MAC);
int blerssi = radiacode->getRSSI();

Serial.printf("BLE Signal: %d dBm\n", blerssi);

Signal Quality Guide

RSSI (dBm) Quality Description
-30 to -50 Excellent Very close, strong signal
-50 to -60 Good Normal operating distance
-60 to -70 Fair Edge of reliable range
-70 to -90 Weak Connection may be unstable
-90 to -100 Very weak About to disconnect
-100 Disconnected No connection

More negative = weaker signal


Test it:

void loop() {
    int blerssi = radiacode->getRSSI();
    if (blerssi != -100) {
        Serial.printf("BLE RSSI: %d dBm\n", blerssi);
    }
    delay(5000);
}

Why This Patch is Needed

The RadiaCode library doesn't expose RSSI by default. This patch:

  1. Adds getRSSI() to BluetoothTransport (accesses BLE client)
  2. Adds getRSSI() to RadiaCode (public API)
  3. Uses safe casting to access the underlying BLE client
  4. Returns -100 when not connected (safe default)

Tested With

  • Arduino IDE: 1.8.19
  • Board: ESP32S3 Dev Module
  • RadiaCode Library: Version by Markus Geiger (mkgeiger)
  • Device: RadiaCode-110
  • Date: March 2026

Request to the RadiaCode library repository so all users can benefit from RSSI access!


Version: 1.0 (Final)
Author: Based on RadiaCode ESP32 Monitor project
License: Same as RadiaCode library

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions