首页 > 解决方案 > Garmin 可穿戴设备和 iOS 设备之间的 BLE 通信

问题描述

我想创建一个 Garmin 可穿戴应用程序(数据字段),它将使用蓝牙 LE(Garmin 上的 BluetoothLowEnergy API 和 iOS 上的 CoreBluetooth)与我的 iOS 应用程序通信。Garmin 的 API 有一个限制 - 它只能作为中央设备工作,因此我将 iPhone 配置为“虚拟”外围设备(我使用自己的调试应用程序和 LightBlue 对其进行了测试)。

我设法在我的 Garmin Vivoactive 3 Music 和我的 iPhone 之间建立了连接,但我仍然有一些问题要让它工作。

从 Garmin 可穿戴设备中,我设法搜索、查找和配对设备(我的 iPhone 虚拟外围设备),以便两者:self.pairedDevice = BluetoothLowEnergy.pairDevice(scanResult)并且BluetoothLowEnergy.getPairedDevices().next()不返回空值。

我遇到的问题是在 Garmin 设备上从未调用过此回调:

function onConnectedStateChanged(device, connectionState) {
    if (connectionState==BluetoothLowEnergy.CONNECTION_STATE_CONNECTED) {
        displayString = "Connected";
    }
    if (connectionState==BluetoothLowEnergy.CONNECTION_STATE_DISCONNECTED) {
        displayString = "Disconnected";
    }
}

此外,当发现我的虚拟外围设备时,我可以在广告数据中看到可用的服务,但是一旦设备配对,调用就会device.getServices()返回一个空的迭代器。

我已经检查过BluetoothLowEnergy.getAvailableConnectionCount()是3,所以连接数限制应该没有问题。有没有办法强制连接?

在 iOS 我做这样的事情:

        let service = CBMutableService(type: serviceCbuuid, primary: true)
        let writeableCharacteristic = CBMutableCharacteristic(type: characteristicCbuuid,
                                                              properties: [.write],
                                                              value: nil,
                                                              permissions: [.writeable])
        service.characteristics = [writeableCharacteristic]
        currentService = service
        peripheralManager = CBPeripheralManager(delegate: self,
                                                queue: DispatchQueue.global(qos: .userInteractive))

然后我添加currentServiceusingperipheralManager?.add(currentService)并在didAdd service回调中通过调用peripheral.startAdvertising(options).

也许我错过了 iOS 端的一些设置来完成这项工作?

标签: iosbluetooth-lowenergycore-bluetoothgarminconnectiq

解决方案


推荐阅读