Page 1 of 1

writeCharacteristic success callback does not work

Posted: 07:34, 11 Sep 2015
by jjww

Code: Select all

app.onSendCommand = function()
{
      
   app.device.writeCharacteristic(
      '6e400002-b5a3-f393-e0a9-e50e24dcca9e',
      new Unit8Array([1,0]),
      function(){console.log('the write is done');},
      function(error){console.log('write error' + error) })
}


Hey all, is there any problem with this code, the function(){console.log('the write is done');} does not work at all, but function(error){console.log('write error' + error) }) can work.

Does the writeCharacteristic() expecting some feedback from ble board?

Re: writeCharacteristic success callback does not work

Posted: 07:38, 11 Sep 2015
by jjww
I was trying to put enablenotification(), in the success callback function

thanks in advance for any help

Re: writeCharacteristic success callback does not work

Posted: 11:49, 12 Sep 2015
by Fredrik
For notifications, you need to do writeDescriptor(... [1,0] ...), not writeCharacteristic. The descriptor is the one with the 2902 UUID.

Characteristics can be defined as writable with or without notification. If write-notification is on, then writeCharacteristic() will wait for the remote device to respond before calling the win callback, otherwise it will be called as soon as the write packet is sent... or so I think.

If neither win or fail callbacks are called, then that's a bug in the plugin, which may be caused by a bug in the OS's BLE stack. We might want to add a timeout.