Window 库中的 scan Window、Interval 和 scanTime 有什么区别?
What is the difference between scan Window, Interval and scanTime in the ESP32_BLE_Arduino Library?
我正在查看 ESP32_BLE_Arduino 库中的基本 BLE_Scan.ino 草图。我已将其修改为先连续扫描 5 次。我想非常快速地进行几次扫描,以便对它们进行平均。 (见下面的代码)
我无法弄清楚扫描间隔、扫描window和scanTime参数之间的区别.
我知道window应该扫描多长时间,这应该每隔间隔发生一次。我不确定 scanTime 参数是什么。
我调整了扫描间隔并扫描 window 到低数字。也将 scanTime 变量设置得尽可能低(1,因为它是一个整数,不能为 0)。 None 这些修复程序似乎允许我进行快速扫描。每次打印 "scan!!" 之间似乎仍有一两秒的延迟。
如能帮助阐明这 3 个参数的作用,或指出我做错了什么,我们将不胜感激。
(另外,我的第一个 post 关于 SO,所以如果我可以解决我提出这个问题的方式,请告诉我,我会的!)
谢谢!!
/*
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
Ported to Arduino ESP32 by Evandro Copercini
*/
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
int scanTime = 1; //In seconds
BLEScan* pBLEScan;
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("");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(50); //interval (how often there is a scan)
pBLEScan->setWindow(49); // window (how long the scans are) must be <= interval
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
//bluetooth scan
for(int x = 0; x < 5; x ++){
BLEScanResults foundDevices = pBLEScan->start(1, true);
Serial.println("Scan!!");
}
delay(200);
}
Scan_Window 配置参数定义扫描持续时间的时间量。 Inquiry_Scan_Window只能小于等于Scan_Interval。 [时间默认值:11.25 毫秒]
Scan_Interval 配置参数定义连续扫描之间的时间量。这定义为从 BR/EDR 控制器开始上一次扫描到开始下一次扫描的时间间隔。 [默认值:2.5 秒]
扫描超时:设备可能会扫描一段有限的时间
我正在查看 ESP32_BLE_Arduino 库中的基本 BLE_Scan.ino 草图。我已将其修改为先连续扫描 5 次。我想非常快速地进行几次扫描,以便对它们进行平均。 (见下面的代码)
我无法弄清楚扫描间隔、扫描window和scanTime参数之间的区别.
我知道window应该扫描多长时间,这应该每隔间隔发生一次。我不确定 scanTime 参数是什么。
我调整了扫描间隔并扫描 window 到低数字。也将 scanTime 变量设置得尽可能低(1,因为它是一个整数,不能为 0)。 None 这些修复程序似乎允许我进行快速扫描。每次打印 "scan!!" 之间似乎仍有一两秒的延迟。
如能帮助阐明这 3 个参数的作用,或指出我做错了什么,我们将不胜感激。
(另外,我的第一个 post 关于 SO,所以如果我可以解决我提出这个问题的方式,请告诉我,我会的!)
谢谢!!
/*
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
Ported to Arduino ESP32 by Evandro Copercini
*/
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
int scanTime = 1; //In seconds
BLEScan* pBLEScan;
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("");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(50); //interval (how often there is a scan)
pBLEScan->setWindow(49); // window (how long the scans are) must be <= interval
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
//bluetooth scan
for(int x = 0; x < 5; x ++){
BLEScanResults foundDevices = pBLEScan->start(1, true);
Serial.println("Scan!!");
}
delay(200);
}
Scan_Window 配置参数定义扫描持续时间的时间量。 Inquiry_Scan_Window只能小于等于Scan_Interval。 [时间默认值:11.25 毫秒]
Scan_Interval 配置参数定义连续扫描之间的时间量。这定义为从 BR/EDR 控制器开始上一次扫描到开始下一次扫描的时间间隔。 [默认值:2.5 秒]
扫描超时:设备可能会扫描一段有限的时间