Domanda

I'm currently working with a Corebluetooth, with my phone acting as central, and a separate peripheral.

I'm successfully reading data from a peripheral device using the didUpdateValueFor delegate method. The problem I'm having is when I'm sending multiple packets of information at the same time.

For instance, I send "abc" first and "def" later. As the central updates the reading upon indication from the peripheral, I should be able to get "abcdef" at the end. This works fine if I am sending indications at a speed of 10 packets per second.

However, once my speed gets to the default indication speed, it's too fast for the central to keep up. I only get the first indication "abc", but I never receive the indication for "def".

Is there a way I can force the didUpdateValueFor method to run concurrently so it captures all incoming notifications regardless of speed?

È stato utile?

Soluzione 2

I think that you mean didUpdateValueForCharacteristic instead of didWriteValueForCharacteristic. Otherwise, the question doesn't seem correct as didWriteValueForCharacteristic can not be used to read data from the remote device (except if you are using error codes for communication - which you shouldn't ;) ).

There are two methods to push data from the peripheral to the central: indications and notifications.

  • Notifications may be discarded if sent too fast or for whatever reasons.
  • Indications can only be sent one at a time (you'll have to wait until the central replies with a confirmation that the indication has been processed, before sending another one!).

I see multiple ways how your current implementation may be incorrect:

  • You are not waiting for the Handle Value Confirmation packet and send the next indication too early.
  • You are sending indications / notifications before the Client Characteristic Configuration has been written by the central.
  • Your peripheral has flagged the characteristic to support both notifications and indications. In this case, Core Bluetooth only supports notifications and doesn't enable indications, in which case you are back at unreliable notifications ([CBPeripheral setNotifyValue:forCharacteristic:])

    If the specified characteristic is configured to allow both notifications and indications, calling this method enables notifications only.

Altri suggerimenti

The best-practices chapter of the Core Bluetooth Programming Guide recommends the use of subscription via setNotifyValue:forCharacteristic: rather than plain reads for characteristics that will change often.

It isn't clear from your question as to whether you are using subscription or polling via readValueForCharacteristic:

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top