esp32-snippets icon indicating copy to clipboard operation
esp32-snippets copied to clipboard

Arduino: how can BLE Client detecting RSSI in Connecting with server,not only for scan?

Open lukascjh opened this issue 6 years ago • 10 comments

I connect two esp32s through the BLE server to the Client, when i use

int ble_rssi = myDevice->getRSSI(); Serial.println(ble_rssi);

in the loop function, become the same value which got in the Scan

I want the Client to always test the signal strength of the server. Is this possible?

thank you in advance

lukascjh avatar Feb 08 '19 14:02 lukascjh

what is myDevice? BLEClient, BLEServer, BLEAdvertisedDevice?

chegewara avatar Feb 08 '19 17:02 chegewara

@chegewara hello, it's BLEAdertisedDevice.

myDevice = new BLEAdvertisedDevice(advertisedDevice);

I want the client to keep detecting RSSI of the server while it is connected, but I failed. Is this possible?

thank you in advance

lukascjh avatar Feb 17 '19 15:02 lukascjh

https://github.com/nkolban/esp32-snippets/blob/810aeb810a15ff6cf8742080ea5a413447cd0b92/cpp_utils/BLEClient.cpp#L366

You need to use it on connected client. At least in this library. myDevice = new BLEAdvertisedDevice(advertisedDevice); is static structure of data, never updated.

This esp-idf function is in gap layer, so in thoery it shouldnt be tied to BLEClient or BLEServer class and maybe moved to BLEDevice. The thing is that you could use it in BLEScan, but most peripheral devices allow only one connection at time and dont advertise when is connected.

PS this code can be cloned to BLEServer, or like i mentioned above moved to BLEDevice

chegewara avatar Feb 18 '19 08:02 chegewara

I am using ble_client in the example. It uses BLEDevice. https://github.com/nkolban/ESP32_BLE_Arduino/blob/master/examples/BLE_client/BLE_client.ino How can this Code be cloned from BLEClient to BLEDevice. I am a beginner and im not very clear how to do it. Can someone help me. thanks

lukascjh avatar Feb 18 '19 14:02 lukascjh

@chegewara Thank you for your reply

lukascjh avatar Feb 18 '19 14:02 lukascjh

i want to try it in loop();

BLEClient* pClient = BLEDevice::createClient(); int rssi= pClient->getRssi(); Serial.println("RSSI Value is :" + rssi);

lukascjh avatar Feb 18 '19 15:02 lukascjh

Use only this in loop:

int rssi= pClient->getRssi();
Serial.println("RSSI Value is :" + rssi);

chegewara avatar Feb 20 '19 06:02 chegewara

@chegewara Thank you I was successful I defined it globally BLEClient* pClient, and use in loop: if (connected) {

int rssi = pClient->getRssi();
Serial.println(rssi);

}

lukascjh avatar Feb 21 '19 11:02 lukascjh

hey im doing a senior design and im in the same boat i need my rssi to read consistent values. What do you mean you globally defined BLEClient*pClient = BLEDevice::createClient();

DeJason-lsng avatar Jan 30 '20 02:01 DeJason-lsng

@DeJason-lsng What he meant with globally defined is he declared the object outside of the loop and setup. This enables a global access for every call/use on it. Ps. Sorry, Im not so good on what they are called.

jrgodin07 avatar Jun 07 '22 03:06 jrgodin07