IOS Bluetooth LE - The Right Way to Record Unanswered

With iOS CoreBluetooth, when sending data with a relatively large amount, it is important to split it into 20 byte blocks, and then write them one at a time to the peripheral object. This is quite easy to do when using WriteWithResponse: write 20 bytes, wait for the callback, write the next 20 bytes, etc.

But what about the WriteWithoutResponse feature? I need to send 1-2kB of data as fast as I can on BLE. WriteWithResponse is very inefficient at the same time because it downloads every 20-byte packet. Error correction and reliability are done at my application level, so I don't need BLE to help the data.

The problem is that WriteWithoutResponse does not give you a callback, because CoreBluetooth cannot know when the data was written. So the question is, how do we properly host sending large amounts of data using WriteWithoutResponse?

The only solution I was thinking of is to do the following:

  • Get the connection interval and the number of packets that can be referenced by one connection interval.
  • Write X packets of 20 bytes each immediately, wait for the Y time and repeat until no data remains. (X = number of packets per connection interval, Y = connection interval)

There are two egregious problems with this approach:

  • CoreBluetooth does not provide us with a connection interval (why?). So there are two options. First: guess. Probably in the worst case or in the average case, depending on your preferred connection settings, I think iOS likes to choose 30 ms. But this is a bad idea, because the central one has the right to completely ignore the proposed parameters. Secondly, you can have peripheral storage and transfer consistent CI to your iOS device. The problem is that you cannot send the CI until the iOS device completes the discovery of services and features and subscribes to the corresponding notification. Thus, you will either have to set an arbitrary fixed delay after connecting before sending the CI, or send a small amount of data from the iOS device, notifying the peripheral device thatthat he is ready. Both create delays and are pretty bad decisions.
  • , . 6. , , 4 . .

, - MTU 20 , . , , ; .

- , ?

+4

Source: https://habr.com/ru/post/1613877/


All Articles