如何解决ESP32 BLE 和 Android 手机 - 存在检测
是否有可能“克服”BLE MAC 地址随机化并检测我自己的 Android 手机的存在?
我正在寻找一种解决方案,如何在不安装 iBeacon 应用程序之类的会耗尽电池电量的情况下,检测到我的手机在 ESP32 的近距离范围内是否存在。
- 我已经开始使用 BLE 嗅探器的示例,它运行良好,但在 Android 上使用 MAC 随机化却毫无用处。
- 然后我转向使用模拟 HID 键盘的解决方案。配对后,当手机进入范围时,它会很好地重新连接。连接后,我可以触发所需的操作,然后我可以关闭 ESP32 蓝牙,以免一直连接。当我需要再次检查手机时,我只需重新打开服务器即可。这将是一个很好的解决方案,但是......我需要检查更多(至少两个)电话。我试图复制 BLEServers 以在两个 simoutinas 之间切换或同时运行,但没有成功 - 要么不可能,要么超出了我对这个 BLE 广告/配对/连接魔法的了解。
- 第三种解决方案是为每部手机配备单独的 ESP - 可行,但只能作为最后的手段
有人已经以某种方式解决了这样的任务吗?
#include <Arduino.h>
#include <BLEDevice.h>
#include <bleutils.h>
#include <BLEServer.h>
#include "BLE2902.h"
#include "BLEHIDDevice.h"
#include "HIDTypes.h"
#include "HIDKeyboardTypes.h"
#include <driver/adc.h>
BLEHIDDevice* hid;
BLECharacteristic* input;
BLECharacteristic* output;
BLEAdvertising *pAdvertising;
BLEServer *pServer;
bool connected = false;
bool restart = false;
class MyCallbacks : public BLEServerCallbacks {
void onConnect(BLEServer* pServer){
connected = true;
Serial.println("Connected");
BLE2902* desc = (BLE2902*)input->getDescriptorByUUID(bleuUID((uint16_t)0x2902));
desc->setNotifications(true);
// NEEDED ACTIONS
}
void ondisconnect(BLEServer* pServer){
connected = false;
Serial.println("disConnected");
BLE2902* desc = (BLE2902*)input->getDescriptorByUUID(bleuUID((uint16_t)0x2902));
desc->setNotifications(false);
restart = true;
}
};
void setup() {
Serial.begin(115200);
Serial.println("Starting BLE work!");
BLEDevice::init("Backpack-MeowMeow");
pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyCallbacks());
pServer->getPeerDevices(true);
hid = new BLEHIDDevice(pServer);
input = hid->inputReport(1); // <-- input REPORTID from report map
output = hid->outputReport(1); // <-- output REPORTID from report map
std::string name = "ElectronicCats";
hid->manufacturer()->setValue(name);
hid->pnp(0x02,0xe502,0xa111,0x0210);
hid->hidInfo(0x00,0x02);
BLESecurity *pSecurity = new BLESecurity();
// pSecurity->setKeySize();
pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND);
hid->startServices();
pAdvertising = pServer->getAdvertising();
pAdvertising->setAppearance(HID_BARCODE);
pAdvertising->addServiceUUID(hid->hidService()->getUUID());
pAdvertising->start();
hid->setbatterylevel(7);
//ESP_LOGD(LOG_TAG,"Advertising started!");
//delay(portMAX_DELAY);
}
void loop() {
if(connected){
delay(10);
}
if (restart) {
restart = false;
pAdvertising->start();
}
delay(50);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。