【问题标题】:iOS bluetooth: Unknown error when writing to characteristiciOS蓝牙:写入特征时出现未知错误
【发布时间】:2013-02-12 12:51:37
【问题描述】:

在我的应用程序中,我发现我的外围设备具有给定的服务。然后,在继续之前检查是否存在所需的所有特征。

当我向我的特征写入值时,回调didWriteValueForCharacteristic: 触发:

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

    NSLog(@"Did write characteristic value : %@ with ID %@", characteristic.value, characteristic.UUID);
    NSLog(@"With error: %@", [error localizedDescription]);
}  

并产生以下输出:

Did write characteristic value : <005c> with ID Unknown (<00005004 1212efde 1523785f eabcd123>)
With error: Unknown error.

该值是正确的,特征的 128 位 UUID 也是如此,但在我的外围设备中,我从未真正得到写入的值。

对可能出现的问题有什么建议吗?

【问题讨论】:

  • 您在 Console 中有没有类似的消息:CoreBluetooth[WARNING]。有时真正的错误是在那里给出的。而且我仍然不知道为什么以及如何抓住它们......
  • 当时没有。回答了我自己的问题

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


【解决方案1】:

我最初发送了 WriteWithoutResponse,将其更改为 WriteWithResponse 给了我 @Larme 在 cmets 中提到的 CoreBluetooth[WARNING] error 13。这个值corresponded to Invalid Attribute Value Length,意味着我发送了错误的数字格式,即我发送了一个 16 位的值,而外围设备期望的是 8 位。

将外设更改为接受 16 位数据解决了该问题。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-26
  • 1970-01-01
  • 2017-04-22
  • 2013-12-21
  • 2015-12-06
  • 1970-01-01
相关资源
最近更新 更多