【问题标题】:How to connect to BLE device that isn't advertising service UUID in iOS app如何连接到不在 iOS 应用程序中广告服务 UUID 的 BLE 设备
【发布时间】:2018-11-15 20:47:09
【问题描述】:

我正在尝试通过 BLE 将 ESP32 模块连接到我的 iPhone,并使用 centralManager.scanForPeripherals(withServices: [carServiceCBUUID], options: nil) 其中let carServiceCBUUID = CBUUID(string: "c0de0001-feed-f00d-c0ff-eeb3d05ebeef")。我正在关注 Ray Wenderlich 的心脏监视器教程,但由于 ESP32 蓝牙模块没有宣传主要的服务 UUID,所以当我做 scanForPeripherals 时它不会找到设备。附上BLE设备上LightBlue信息的截图。有没有办法可以更改广告数据,以便为服务做广告?我在 ESP32 https://thejeshgn.com/2018/06/11/esp32-ble-building-an-echo-service-gatt-server/

上运行此代码

screenshot of LightBlue connection

【问题讨论】:

  • 问题不在 Swift 上。如果您不公开宣传该服务,您就找不到这种方式。你需要做centralManager.scanForPeripherals(withServices: nil, options: nil)。我猜BLEAdvertising *pAdvertising = pServer->getAdvertising(); 是您可能想要明确宣传该服务的地方。

标签: ios swift arduino bluetooth-lowenergy esp32


【解决方案1】:

根据documentation of scanForPeripheralsWithServices:options:serviceUUIDs 参数可以是nil - 在这种情况下

无论支持的服务如何,都会返回所有发现的外围设备(不推荐)

因此,除非您打算在应用程序处于后台时使用后台模式进行扫描,否则您可以将nil 作为serviceUUIDs 参数传递

【讨论】:

    猜你喜欢
    • 2014-04-23
    • 1970-01-01
    • 2022-08-12
    • 2019-08-08
    • 1970-01-01
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多