【问题标题】:Measuring bluetooth connection force with ESP32用ESP32测量蓝牙连接力
【发布时间】:2019-06-01 07:26:13
【问题描述】:

如何测量 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);
}`

【问题讨论】:

    标签: bluetooth arduino bluetooth-lowenergy esp32


    【解决方案1】:

    只需向您的 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);
        }
    }; 
    

    【讨论】:

      【解决方案2】:

      在wifi中我正在使用这个功能:

      // 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;
      }
      

      你的 BLE 功能与 WiFi.RSSI() 相同:(参见 github 源代码)

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-12-24
        • 2021-03-20
        • 2020-11-09
        • 2022-11-18
        • 2023-02-23
        • 2018-06-25
        • 2019-10-23
        相关资源
        最近更新 更多