-
Notifications
You must be signed in to change notification settings - Fork 715
BLE Server Get RSSI, MAC, Name etc #1017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
After a while I manage to do it:
memcpy(&peerAddress, param->connect.remote_bda, 6); //this way youll have the peerdevice addres } Serial.print("RSSI from gap event"); //be carefull with the speed you ask for the rssi if you have problems } |
hi, i tried using this but im getting an error that peerAddress was not declared in this scope, i need to do the same thing, get the rssi of the client connected to my esp, can you please help me on this im new to the ble concept |
I also got the same error like KanaJayy, What should i do to solve this problem ? |
@hoangducnghi2207 did you get it to work? |
I dont remember anything about what I did here, it was too long ago. I'll give you the link to the full project so you can check it out. https://github.com/TheUruguayo/BLE-ESP32-tracking-robot |
I will unsubscribe to this so I will not get further emails about it. If anyone has issues that have no answer my recomendation is to read the documentation. |
Hello everyone,
I want to do something that seems really elemental to a server, but at this point I'm not available to do.
I want my BLE server to report, the RSSI, MAC and name of connected devices (first 2 most of all). The scan is not good for me, I need to know which ones are connected.
It seems that the function get RSSI is implemented in the client side (which I don't need) is there a way of doing this. I've seen a post that does the following (#893), but is not working for me, the values of that gives are apparently random, (RSSI and MAC, are very different from the scan).
I want to call a function, lets say myserver.getRssi() or simply getRssi(), and have the RSSI and mac of a device connected to me. At this stage only one client is connected. I do not understand how this libraries work yet, and how to move functions around, so any tips on that regard will be appreciated.
(I'm working on a robot that follows this signal).
#include <BLEUtils.h>
#include <BLE2902.h>
#include <BLEScan.h>
String valor;
int aleatorio1;
int aleatorio2;
String alea1;
String alea2;
String alea3;
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
//para el servicio 2
#define SERVICE2_UUID "45ecddcf-c316-488d-8558-3222e5cb9b3c"
#define CHARACTERISTIC2_UUID "4a78b8dd-a43d-46cf-9270-f6b750a717c8"
int data;
int LED_BUILTIN = 2;
bool deviceConnected = false;
int CUTOFF = -60;
class myServerCallback : public BLEServerCallbacks {
void onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param) {
}
void onDisconnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param) {
}
};
class MyCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string value = pCharacteristic->getValue();
};
static void my_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param) {
Serial.print("RSSI status");
Serial.println(param->read_rssi_cmpl.status);
Serial.print("RSSI ");
Serial.println(param->read_rssi_cmpl.rssi);
Serial.print("Address ");
Serial.println(BLEAddress(param->read_rssi_cmpl.remote_addr).toString().c_str());
}
void setup() {
Serial.begin(115200);
pinMode (LED_BUILTIN, OUTPUT);//pin y su salida
BLEDevice::init("Hide&Seek");// nombre del dispositivo bl
BLEServer *pServer = BLEDevice::createServer(); // Create the BLE Server
BLEService *pService = pServer->createService(SERVICE_UUID);
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_NOTIFY |
BLECharacteristic::PROPERTY_WRITE
);
pServer->setCallbacks(new myServerCallback());
pCharacteristic->setCallbacks(new MyCallbacks());
BLEDevice::setCustomGapHandler(my_gap_event_handler);
pCharacteristic->setValue("Iniciado.");
pCharacteristic->addDescriptor(new BLE2902());
pService->start();
BLEAdvertising *pAdvertising = pServer->getAdvertising();
pAdvertising->start();
}
void loop() {
delay(1000);
aleatorio1 = random(1,50); // Crea el numero aleatorio.
alea1 = (String) aleatorio1; // Lo convierte en String.aleatorio
aleatorio2 = random(100,200); // Crea el numero aleatorio.
alea2 = (String) aleatorio2; // Lo convierte en String.aleatorio
//alea3 = alea1 + "," + alea2;
// BLEScan *scan = BLEDevice::getScan();
// scan->setActiveScan(true);
// BLEScanResults results = scan->start(1);
// int best = CUTOFF;
// Serial.print("---------NUEVO ESCANER-------------------- ");
// Serial.print('\n');
// for (int i = 0; i < results.getCount(); i++) {
// BLEAdvertisedDevice device = results.getDevice(i);
//
// int rssi = device.getRSSI();
// if ("Pixel 3a XL"==device.getName()) {
// alea3=device.getName().c_str()+(String)device.getRSSI();
// }
// Serial.print("----------------------------- ");
// Serial.print('\n');
// Serial.println(device.getName().c_str());
// Serial.println((String)device.getRSSI());
// Serial.println(device.getAddress().toString().c_str());
// Serial.print('\n');
// if (rssi > best) {
// best = rssi;
// }//endif
// }//endfor
delay(15000);
The text was updated successfully, but these errors were encountered: