3

In my application I discover my peripheral with a given service. I then check that all characteristics wanted are present before moving on.

When I write a value to my characteristics, the callback didWriteValueForCharacteristic: trigger:

- (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]);
}  

and yields this output:

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

The value is correct, same goes for the 128bit UUID of the characteristic, but in my peripheral I never actually get a value written.

Any suggestions to what might be wrong?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
chwi
  • 2,752
  • 2
  • 41
  • 66
  • Did you have in the *Console* a message like: *CoreBluetooth[WARNING]*. Sometimes the real error is given there. And I still don't know why and how to catch them... – Larme Feb 12 '13 at 15:10
  • Not at the time. Answered my own question – chwi Feb 13 '13 at 07:23

1 Answers1

4

I originally sent a WriteWithoutResponse, changing this to WriteWithResponse gave me a CoreBluetooth[WARNING] error 13 as mentioned by @Larme in the comments. This value corresponded to Invalid Attribute Value Length, meaning I sent the wrong number format, i.e I sent a 16bit value while the peripheral expected 8bit.

Changing the peripheral to accept 16bit data solved the issue.

chwi
  • 2,752
  • 2
  • 41
  • 66
  • How did you discover that error 13 means "Invalid attribute value length"? I've been searching everywhere for a list of these error codes, with no luck. (I'm getting unknown error 10.) – Joe Strout May 21 '13 at 14:41
  • @JoeStrout http://developer.apple.com/library/ios/#documentation/CoreBluetooth/Reference/CoreBluetooth_Constants/Reference/reference.html your error is `CBATTErrorAttributeNotFound` – chwi May 21 '13 at 18:38
  • But What is the solution? – Mrug Mar 17 '15 at 11:06
  • @Mrug sending the correct value format solved the issue – chwi Mar 17 '15 at 11:11
  • Can you please help me on a issue related to this : http://stackoverflow.com/questions/29095333/corebluetooth-writing-data-from-central-to-peripheral – Mrug Mar 17 '15 at 11:28
  • I am using WriteWithResponse, also getting Unknown Error – Vineesh TP Dec 03 '15 at 10:57
  • We are able to send data properly after connection but sometimes it becomes not ready to send (Connection is still). Do you know what causes this issue? @chwi – Rushang Prajapati Dec 24 '21 at 11:14