简体   繁体   中英

Measuring bluetooth connection force with ESP32

How can I measure the bluetooth connection force with ESP32? I'm using the available example of BLE to detect the possibility of connection, but I need to measure its strength. Thank you.

I'm using:

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>

int scanTime = 30; //In seconds

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
    void onResult(BLEAdvertisedDevice advertisedDevice) {
      Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
    }
};

void setup() {
  Serial.begin(115200);
  Serial.println("Scanning...");

  BLEDevice::init("");
  BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  BLEScanResults foundDevices = pBLEScan->start(scanTime);
  Serial.print("Devices found: ");
  Serial.println(foundDevices.getCount());
  Serial.println("Scan done!");
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
}`

Just a few lines added to your MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks :

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
    void onResult(BLEAdvertisedDevice advertisedDevice) {
      Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str
      int rssi = advertisedDevice.getRSSI();
      Serial.print("Rssi: ");
      Serial.println(rssi);
    }
}; 

in wifi i am using this function:

// Take a number of measurements of the WiFi strength and return the average result.
int getStrength(int points){
  long rssi = 0;
  long averageRSSI=0;

  for (int i=0;i < points;i++){
    rssi += WiFi.RSSI(); // put your BLE function here
    delay(20);
  }

  averageRSSI=rssi/points;
  return averageRSSI;
}

and you have the same function for BLE than WiFi.RSSI(): (see in github source code)

int BLEAdvertisedDevice::getRSSI() {
   return m_rssi;
} // getRSSI

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM