【问题标题】:Is Data Written to a BLE Characteristic Returned after Write数据是否写入到写入后返回的 BLE 特性
【发布时间】:2018-06-01 16:32:35
【问题描述】:

我有一个工作的 BLE 应用程序,它从扫描仪读取数据,并在开始读取之前将配置发送到扫描仪。我使用以下代码向扫描仪发送字符串。

let configItem = "BD1"

let data = configItem?.data(using: String.Encoding.ascii)

peripheral.writeValue(data!, for: characteristic, type: .withResponse)

我在回调中打印特征名和值

func peripheral(_:didWriteValueFor:CBCharacteristic:Error?)
{
    let value = String(data: characteristic.value!, encoding: .ascii)!

    print("Wrote characteristic value: " + value + "; for characterisitc: " + characteristic.uuid.description)
}

打印出来的值不是我写的配置数据,而是一些旧扫描仪读取的数据。令人惊讶的是,即使在应用关闭后,旧的读取数据仍然存在。

那么回调中发送的特征是否有效,是否包含写入的数据?

【问题讨论】:

    标签: swift bluetooth-lowenergy characteristics


    【解决方案1】:

    事实证明这是一个特定于设备的“功能”。扫描仪不会返回对特征写入的响应,但我仍然会收到回电,因此数据只是陈旧的。并且测试显示配置字符串从未到达扫描仪。这种情况的解决方案是发送数据“.withoutResponse”。

    【讨论】:

      猜你喜欢
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 2018-06-13
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多