bluetooth - 用ESP32测量蓝牙连接力
问题描述
如何使用 ESP32 测量蓝牙连接力?我正在使用 BLE 的可用示例来检测连接的可能性,但我需要测量它的强度。谢谢你。
我在用着:
#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);
}`
解决方案
只需向您的 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);
}
};
推荐阅读
- r - 如何绑定许多数据帧?
- r - 使用循环加载多个数据集 r
- java - Mac Os Catalina 阻止 jar 应用程序进入文件夹
- mysql - 返回当前或下周末的结果
- python - 使用不受欢迎的 pyproject.toml 作者更改 Python 诗歌初始化新项目
- android - 如何使用 MAC 在真正的 android 设备上测试应用程序
- python-3.x - condition statements in pandas
- c# - 将属性名称作为参数传递
- android - 存根方法时获取 InvalidUseOfMatchersException
- javascript - 将 node.js postgres 查询结果保存在变量中