简体   繁体   English

如何在iOS应用中连接到不是广告服务UUID的BLE设备

[英]How to connect to BLE device that isn't advertising service UUID in iOS app

I am trying to connect an ESP32 module to my iPhone via BLE and am using centralManager.scanForPeripherals(withServices: [carServiceCBUUID], options: nil) where let carServiceCBUUID = CBUUID(string: "c0de0001-feed-f00d-c0ff-eeb3d05ebeef") . 我试图通过BLE将ESP32模块连接到我的iPhone,并使用centralManager.scanForPeripherals(withServices: [carServiceCBUUID], options: nil) ,其中let carServiceCBUUID = CBUUID(string: "c0de0001-feed-f00d-c0ff-eeb3d05ebeef") I am following Ray Wenderlich's heart monitor tutorial but since the ESP32 bluetooth module is not advertising the main Service UUID, it won't find the device when I do scanForPeripherals . 我正在关注Ray Wenderlich的心脏监护仪教程,但是由于ESP32蓝牙模块没有发布主要的服务UUID,因此当我执行scanForPeripherals时,它将找不到该设备。 Attached is the screenshot of the LightBlue information on the BLE device. 附件是BLE设备上的LightBlue信息的屏幕截图。 Is there a way I can change the advertising data so I can advertise the service? 有什么方法可以更改广告数据以便为服务做广告? I am running this code on the ESP32 https://thejeshgn.com/2018/06/11/esp32-ble-building-an-echo-service-gatt-server/ 我在ESP32上运行此代码https://thejeshgn.com/2018/06/11/esp32-ble-building-an-echo-service-gatt-server/

screenshot of LightBlue connection LightBlue连接的屏幕截图

According to documentation of scanForPeripheralsWithServices:options: the serviceUUIDs parameter can be nil - in that case 的文件scanForPeripheralsWithServices:options:serviceUUIDs参数可以是nil -在这种情况下

all discovered peripherals are returned regardless of their supported services (not recommended) 不论支持的服务如何,都将返回所有发现的外围设备(不推荐)

So unless you are planning to use background modes to scan when app is in background, you can just pass nil as serviceUUIDs parameter 因此,除非您打算使用后台模式扫描应用程序在后台运行的时间,否则只需将nil作为serviceUUIDs参数传递即可

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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