Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CurieBLE: characteristic.writeInt(...) reports success when peripheral responds with error #517

Open
sandeepmistry opened this issue Mar 29, 2017 · 4 comments
Labels

Comments

@sandeepmistry
Copy link
Contributor

Similar to #516, but for write requests. We should also see if the same applies to characteristic.subscribe().

Testing with the 2.0.1RC2.1 JSON:

Arduino sketch:

#include <CurieBLE.h>

void setup() {
  Serial.begin(9600);

  while (!Serial);

  Serial.println("BLE Central - Read + Write test");

  // initialize the BLE hardware
  BLE.begin();

  // start scanning for peripheral
  BLE.scanForName("rwfail");
}

void loop() {
 // check if a peripheral has been discovered
  BLEDevice peripheral = BLE.available();

  if (peripheral) {
    // discovered a peripheral, print out address, local name, and advertised service
    Serial.print("Found ");
    Serial.println(peripheral.address());

    BLE.stopScan();

    Serial.println("Connecting ...");
    if (peripheral.connect()) {
      Serial.println("Connected");
    } else {
      Serial.println("Failed to connect!");
      while(1);
    }
    
    // discover peripheral attributes
    Serial.println("Discovering attributes ...");
    if (peripheral.discoverAttributes()) {
      Serial.println("Attributes discovered");
    } else {
      Serial.println("Attribute discovery failed.");
      peripheral.disconnect();
      while(1);
    }

    BLECharacteristic c = peripheral.characteristic("fa12");


    while (peripheral.connected()) {
      Serial.println("reading ...");
      if (c.read()) {
        // should not happen
        Serial.println("read success");
      } else {
        // expected
        Serial.println("read fail");
      }

      Serial.println("writing ...");
      if (c.writeInt(42)) {
        // should not happen
        Serial.println("write success");
      } else {
        // expected
        Serial.println("write fail");
      }


      delay(1000);
    }


    BLE.scan();
  }
}

Node.js bleno test app:

var bleno = require('bleno');

var BlenoPrimaryService = bleno.PrimaryService;
var BlenoCharacteristic = bleno.Characteristic;

console.log('bleno - read + write fail');

bleno.on('stateChange', function(state) {
  console.log('on -> stateChange: ' + state);

  if (state === 'poweredOn') {
    bleno.startAdvertising('rwfail', ['fa11']);
  } else {
    bleno.stopAdvertising();
  }
});

bleno.on('advertisingStart', function(error) {
  console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));

  if (!error) {
    bleno.setServices([
      new BlenoPrimaryService({
        uuid: 'fa11',
        characteristics: [
          new BlenoCharacteristic({
            uuid: 'fa12',
            properties: ['read', 'write'],
            onReadRequest: function(offset, callback) {
              console.log('onReadRequest');
              callback(BlenoCharacteristic.RESULT_UNLIKELY_ERROR);
            },
            onWriteRequest: function(data, offset, withoutResponse, callback) {
              console.log('onWriteRequest');
              callback(BlenoCharacteristic.RESULT_UNLIKELY_ERROR);
            }
          })
        ]
      })
    ]);
  }
});

characteristic.writeInt(42) is return true even though the GATT write request fails. I expect it to return false to indicate failure.

Packet Logger trace:

screen shot 2017-03-29 at 12 47 43 pm

@noelpaz
Copy link
Contributor

noelpaz commented Mar 29, 2017

Issue confirmed:

issue517.zip

image

@SidLeung SidLeung added this to the Elnath milestone Apr 4, 2017
@SidLeung SidLeung added the bug label Apr 4, 2017
@SidLeung SidLeung self-assigned this Apr 4, 2017
@novashah
Copy link

@sandeepmistry Please review and close.

@sandeepmistry
Copy link
Contributor Author

Hi @novashah,

I believe this is still an issue, since PR #518 (or an equivalent) has not been merged in.

@mxwang101
Copy link

@noelpaz 👍 Cloud you please tell me what kinds of tools you used for to Packet Logger trace? I have same problem, but no tools to trace it. Thanks

@kitsunami kitsunami removed this from the Elnath milestone Aug 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants