简体   繁体   English

BLE设备无法连续发送多个GATT通知

[英]BLE device fails to send multiple GATT notifications in a row

I'm experimenting with Bluetooth LE with GATT and I have encountered a problem I need your help with. 我正在尝试使用GATT的蓝牙LE,我遇到了一个需要你帮助的问题。

I'm sending Data back and forth between a Client (One Android Application and one iOS Application) and a Server (Currently running Bleno). 我在客户端(一个Android应用程序和一个iOS应用程序)和一个服务器(当前运行Bleno)之间来回发送数据。

I have chosen an architecture with one Characteristic only (which I think of as a Socket) and I write Requests on it from the Clients. 我选择了一个只有一个特性的架构(我认为它是一个Socket),我从客户端编写请求。 The Server responds to the request with a Notification. 服务器使用通知响应请求。 Notifications can only be 20 Bytes long, so I sometimes have to split the response into several Chunks and send it as separate notifications. 通知只能是20字节长,因此我有时必须将响应拆分为多个块并将其作为单独的通知发送。

My problem is that when I split the response into 10 Chunks or more, they are never received on the Clients. 我的问题是,当我将响应分成10块或更多时,它们永远不会在客户端上收到。 (For 1..9 Chunks everything works as expected). (对于1..9块,一切都按预期工作)。

I have used HCIDump ( hcidump -i hci0 -X ) to inspect the commands sent over BLE both when it fails and when it succeeds. 我已经使用HCIDump( hcidump -i hci0 -X )来检查在BLE发生故障和成功时发送的命令。

The following output is taken from HCIDump when sending the notifications succeeds: 发送通知成功时,从HCIDump获取以下输出:

< ACL data: handle 69 flags 0x00 dlen 27
ATT: Handle notify (0x1b)
  handle 0x000c
  value 0x06 0x09 0x46 0x46 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47

followed by:

> HCI Event: Number of Completed Packets (0x13) plen 5
handle 69 packets 1

(for each of the Notification Chunks) (对于每个通知块)

The next output is taken from HCIDump when failing to send notifications: 未能发送通知时,下一个输出来自HCIDump:

< ACL data: handle 68 flags 0x00 dlen 27
ATT: Handle notify (0x1b)
  handle 0x000c
  value 0x08 0x0a 0x46 0x46 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47 0x47

But I get no "Completed packets" events, but instead a simple device: disconnected . 但我没有得到“已完成的数据包”事件,而是一个简单的device: disconnected

I have yet to figure out on which side of the communication the error occurs. 我还没弄清楚错误发生在通信的哪一侧。 As far as I know, it could be either the Clients not being able to receive and Ack the Notifications "fast" enough, our because I'm queueing too many requests on the Server side. 据我所知,它可能是客户端无法“快速”接收和确认通知,因为我在服务器端排队太多请求。

I have tested to add Sleep() commands between sending each notification on the Server. 我已经测试过在服务器上发送每个通知之间添加Sleep()命令。 It does work, but feels too unstable. 它确实有效,但感觉太不稳定了。 For 10 notifications, I needed 6 ms delay for the notifications to come through, for 30 notifications, I needed 10 ms delay. 对于10个通知,我需要6毫秒的延迟才能通知,对于30个通知,我需要10毫秒的延迟。

Does anyone know where to start looking for the problem? 有谁知道从哪里开始寻找问题? I'm happy to provide more information if needed. 如果需要,我很乐意提供更多信息。

Notes: 笔记:

  • I have tested and found exactly the same limits with my Android and iOS device. 我已经测试过并发现了与Android和iOS设备完全相同的限制。

There's a limit to how many "chunks" you can send before the queue gets filled. 在队列填满之前,您可以发送多少“块”是有限制的。 You have to wait for the central to confirm that it's ready to receive more data before you send the next chunk. 在发送下一个块之前,您必须等待中心确认它已准备好接收更多数据。

In bleno's case you'd wait to get back an indication in your characteristic's onIndicate callback before sending the next chunk: 在bleno的情况下,你等待在发送下一个块之前在你的特征的onIndicate回调中找回一个指示:

var Characteristic = bleno.Characteristic;

var characteristic = new Characteristic({
    uuid: 'fffffffffffffffffffffffffffffff1',
    properties: [ ... ],
    secure: [ ... ],
    value: null,
    onIndicate: null // <-- Right here
});

At least for iOS, you don't have to change your implementation to get an indication back. 至少对于iOS,您不必更改实现以获得指示。 As long as you've called setNotifyValue:forCharacteristic: you also enable indications, as per Apple's documentation: 只要您调用了setNotifyValue:forCharacteristic:您还可以根据Apple的文档启用指示:

Sets notifications or indications for the value of a specified characteristic. 设置指定特征值的通知或指示。

I'm not sure if more work is required for Android. 我不确定Android是否需要更多工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM