4

I am trying to send a response from central to peripheral. The code was worked fine twice. Suddenly didReceiveWriteRequest is not getting called. I didn't make any changes even.The properties given at peripheral are CBCharacteristicsPropertyNotify | CBCharacteristicsPropertyWriteWithResponse and CBCharacteristicPropertyWrite. The permissions given are CBAttributePermissionsWriteable | CBAttributePermissionsReadable. At central I have given setNotifyValue=YES in didDiscoverCharacteristicsForService method. And this is how I try to write from central:

[peripheral writeValue:data forCharacteristic:self.peripheralCharacteristicn type:CBCharacteristicWriteWithResponse];

I can't find any mistakes in what I have done. For some reason, didReceiveWriteRequest is not getting called at Peripheral. Please advice.

Sunny Shah
  • 12,990
  • 9
  • 50
  • 86
Kalpa-W
  • 348
  • 3
  • 22

2 Answers2

0

I had faced same problem. Couple of things you can try:

  1. From the central side, try changing the 'write to characteristic' API to with response / without response appropriately.

  2. On the peripheral side (which is your iOS device), try using either of the 'didReceiveWrite':

i. didReceiveWriteRequests

ii. didReceiveWrite

iii. didReceiveWriteRequest - Don't miss the singular 'Request' in the name. This one receives only one object of CBATTRequest, as opposed to an array of requests in case of the first API 'didReceiveWriteRequests'

zeuschyant8
  • 453
  • 7
  • 14
0

I was stuck with the same issue - my didReceiveWrite callback wasn't being executed. My solution was not just implementing the ".write" CBCharacteristic property, but rather the ".writeWithoutResponse", as on my Central-side (which happens to be a Raspberry Pi running BluePy), my "write" request wasn't requiring a response.

The characteristic that works looks something like this:

        myChar1 = CBMutableCharacteristic(type: CBUUID(nsuuid: UUID(uuidString: MYUUID)), properties: [.writeWithoutResponse], value: nil, permissions: [.readable, .writeable])