BLE server, need the RSSI of its clients to perform action.

Kikolobo
Posts: 3
Joined: Mon Jul 25, 2022 7:05 pm

BLE server, need the RSSI of its clients to perform action.

Postby Kikolobo » Mon Jul 25, 2022 7:45 pm

Hello all,

I am working on an application that uses BLE as a server in an ESP32. Clients connect to it and send a code to open a door. This works fine but I need to do this when the RSSI of the device goes above a certain threshold or power to make sure the Client device is close to the chip server.

I implemented this using the Arduino BLE abstraction of ESP32 using the server mechanism.

Is there a way to retrieve the RSSI value when a characteristic is written to? Like in a server or characteristic callback ?

Ir a way to retrieve the connected clients to the server so we can read or get their respective RSSI VALUÉ?

Any help would be appreciated.

Kikolobo
Posts: 3
Joined: Mon Jul 25, 2022 7:05 pm

Re: BLE server, need the RSSI of its clients to perform action.

Postby Kikolobo » Wed Jul 27, 2022 5:39 pm

Anyone?

Should I switch to client instead of server ? But I need multiple connections.

Any help welcomed.

Kikolobo
Posts: 3
Joined: Mon Jul 25, 2022 7:05 pm

Re: BLE server, need the RSSI of its clients to perform action.

Postby Kikolobo » Sun Aug 07, 2022 10:22 pm

Just in case someone needs to do this. The way I Solved it is by doing the following:

1) Right after:

Code: Select all

BLEDevice::init("DeviceName");
Add:

Code: Select all

BLEDevice::setCustomGapHandler(my_gap_event_handler);
Where : my_gap_event_handler is a callback function that looks like this:

Code: Select all

static void my_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param) {
}
In here, you check the param to extract the RSSI :

Code: Select all

static void my_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param) {
  String devAddress = String(*param->read_rssi_cmpl.remote_addr);
  int8_t rssi = param->read_rssi_cmpl.rssi;
}

In order to request the RSSi you need to ask for it somewhere, in my case, I do this in the BLECharacteristicCallbacks function OnWrite because it fits my application, but this can be done anywhere you have access to the remote device address. You just call:

Code: Select all

esp_err_t rc = ::esp_ble_gap_read_rssi(param->read.bda);

I hope this helps someone!

aXXo250
Posts: 2
Joined: Sat Aug 10, 2024 2:14 pm

Re: BLE server, need the RSSI of its clients to perform action.

Postby aXXo250 » Tue Aug 27, 2024 11:54 pm

Thanks for this, ive been looking for exactly this online for a while now. :idea:

oh btw did you use the server example in the end?
and what security did you use?

i see it was a while ago u posted this so hopefully your still active, and even better have progressed with it.

Thanks again

Who is online

Users browsing this forum: No registered users and 33 guests