0

I was wondering If I need to wait for a response from the server that a command was executed before executing another command or if the BLE stack takes care of this under the hood so to speak.

For example, I want to write to a characteristic and then read from it. Should I execute these commands in tandem or should I wait for the onWriteRequest callback method to fire before I send a read request?

If yes to former question, how many resend attempts will the BLE stack make, and how long does it wait for a response before resending a packet?

the_prole
  • 8,275
  • 16
  • 78
  • 163

1 Answers1

0

With the GATT protocol you can only have one outstanding operation at a time. You must wait for a response until you can send the next request. For Android you therefore have to wait for the onCharacteristicWrite until you can send, for example, a read request. I guess it's the same on iOS.

The Bluetooth stack sends the request packet to the Bluetooth controller in the phone. The Bluetooth controller which implements the link layer will then send the packet at the next opportunity (connection event). If the packet is not acknowledged it will resend the same packet until acknowledged or the link times out (supervision timeout). The default timeout is 5 seconds (it was 20 seconds in earlier Android versions). The peripheral can however change the timeout value by issuing a Connection Parameter Update Request.

Emil
  • 16,784
  • 2
  • 41
  • 52