Possible to fail BLE service characteristic write?

Posted on
  • I have a Bluetooth characteristic onWrite function as so:

    onWrite: function(evt) {
      let value = new DataView(evt.data).getUint32(0, /*littleEndian=*/ true);
      // Do something with value.
     },
    

    I'd like to validate the value -something like this:

    onWrite: function(evt) {
      let value = new DataView(evt.data).getUint32(0, /*littleEndian=*/ true);
      if (value < 0)
        throw 500; // Raise some kind of exception
      // value is good, do something with value.
     },
    

    Is this supported?

  • You mean you want to create some kind of Bluetooth error on the other device that is writing that value?

    I'm afraid that's not supported, but you could create another 'status' characteristic with 'notify' on it, and then when there was an error you could notify with an error code on that characteristic?

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Possible to fail BLE service characteristic write?

Posted by Avatar for cmumford @cmumford

Actions