【问题标题】:What the custom UUID mean for BLE in IOS Sample?IOS 示例中的自定义 UUID 对 BLE 意味着什么?
【发布时间】:2014-06-01 07:59:23
【问题描述】:

我是 iOS 开发的新手,正在研究 iOS 的 Bluetooth Low Energy (BLE, Bluetooth 4.0)

我研究了这个链接BTLE Central Peripheral Transfer的示例代码。

这个链接里还有另一个类似的例子iOS 7 SDK: Core Bluetooth - Practical Lesson

以上两个链接上的应用程序在BLE 的基础上讨论了两个IOS 设备之间的send and receive the text data。 App可以选择central或者Peripheralcentral会接收Peripheral发送的文本数据。

它定义了UUID,就像header file中的以下代码一样。

#define TRANSFER_CHARACTERISTIC_UUID    @"08590F7E-DB05-467E-8757-72F6FAEB13D4"

Central连接到Peripheral后,发现Peripheral的特征。

如果 UUID 等于 TRANSFER_CHARACTERISTIC_UUID ,则使用 setNotifyValue:YES 订阅它,如下代码所示。

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
    // Again, we loop through the array, just in case.
    for (CBCharacteristic *characteristic in service.characteristics) {

        // And check if it's the right one
        if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]]) {

            // If it is, subscribe to it
            [peripheral setNotifyValue:YES forCharacteristic:characteristic];
        }
    }

    // Once this is complete, we just need to wait for the data to come in.
}

The question is like the following:

First Question:

我在Bluetooth Development Portal 中找不到这个UUID:@"08590F7E-DB05-467E-8757-72F6FAEB13D4"。 这是 uuidgenterminal 中创建的吗?

The second Question:

如果我是 Central ,并且我已经像上面的代码一样使用 setNotifyValue:YES 订阅了 characteristic

BLE 会通过以下代码告诉 Central 有来自 Peripheral 的新数据发送,这个概念是否正确?

- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error

我是IOS开发和BLE的新手。

提前致谢。

【问题讨论】:

  • 对于第一个问题:长 UUID 是自定义 UUID(而标准 UUID 使用 4hex)。这意味着它们不尊重任何标准,因为它们还不存在或者因为它们是特定的/专有的。

标签: ios objective-c bluetooth bluetooth-lowenergy core-bluetooth


【解决方案1】:

第一个问题:

  • 是的,Apple 甚至建议在各种 WWDC 视频中使用 uuidgen 生成这些 UUID。蓝牙 SIG 未对 128 位 UUID 进行标准化,您可以使用它们来运行自己的配置文件。

第二个问题:

  • 是的,您首先发现服务,然后是特征,然后是setNotifyValue:YES。从现在开始,您将通过[-CBPeripheralDelegate didUpdateValueForCharacteristic:error:] 收到来自外围设备的通知。当您手动读取特征时,将调用相同的回调(无法区分读取响应和核心蓝牙中的通知)。

【讨论】:

猜你喜欢
  • 2014-09-26
  • 1970-01-01
  • 2017-05-14
  • 2011-12-28
  • 2020-10-12
  • 2011-06-11
  • 2010-10-02
  • 2013-01-16
  • 1970-01-01
相关资源
最近更新 更多